Edit report at http://bugs.php.net/bug.php?id=49957&edit=1

 ID:                 49957
 Comment by:         bob_the_builder at gmail dot com
 Reported by:        greg at imagiclab dot com
 Summary:            Need magic method for every data type
 Status:             Bogus
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   unix
 PHP Version:        5.3.0
 Block user comment: N

 New Comment:

@johannes



the problems you are mentioning are not new to OO languages. The same
problem might arise in C++ for example when 2 valid implicit cast exist.
This would simply raise an error. The programmer has to ability to
specify casts as explicit, so they will be invoked only if it is
explicity requested. Therefore he can only provide a single impicit cast
to prevent such an error. The same scheme could be applied in php. If
more than one implicit cast is found an E_USER error could be raised.


Previous Comments:
------------------------------------------------------------------------
[2009-10-23 15:39:34] greg at imagiclab dot com

Ok i see you point but other are not as complex like



__toResource would be create for connect on demand db classes





you can also only have the magic methods for float and int called if you


are specifically cast like (int)$Object

------------------------------------------------------------------------
[2009-10-23 10:24:21] johan...@php.net

This was discussed and leads to too many unclear situations. Like should
 $a + $b call toFloat or toInt or what? What about $a < $b? Maybe a
string comparison.



In the end implementing this gives more trouble than where it helps.

------------------------------------------------------------------------
[2009-10-22 15:23:46] greg at imagiclab dot com

Description:
------------
Need magic method for every data type.



Why have a incomplete magic method list. Why not a __toInt and 

__toResource.



We are trying to change a legacy system to connect to mysql on demand 

and would love a __toResource magic method.  



Also anyone who uses class based enums would like a __toInt to convert 

the enum to is int valyue and to use __toSting to convert the enum to 

its label.

Reproduce code:
---------------
---

>From manual page: language.oop5.magic

---





------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=49957&edit=1

Reply via email to