From:             131 dot php at cloudyks dot org
Operating system: Linux
PHP version:      5.2.6
PHP Bug Type:     Feature/Change Request
Bug description:  Magic function __cast($to) 

Description:
------------
The same way __toString is implemented, i suggest new magics functions
__toBool, __toInt, __toArray, or maybe, as suggested on php.general, a
generic magic function __cast($type){}

An example of implementation could be
class error extends exeption {
 __toBool(){return false; }
}




Reproduce code:
---------------
<?
//by C. Guthrie
class MyClass {
  function __cast($type)
  {
   switch ($type)
   {
     case 'string':
       return 'Foo';
     case 'array':
       return array('Foo');
     case 'DomDocument':
       // etc.
   }
  }
}
$my = new MyClass();


$xml = (DomDocument)$foo;

It would return the result of __cast called with $type == 'DomDocument'.



-- 
Edit bug report at http://bugs.php.net/?id=46128&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=46128&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=46128&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=46128&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=46128&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=46128&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=46128&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=46128&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=46128&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=46128&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=46128&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=46128&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=46128&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=46128&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=46128&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=46128&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=46128&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=46128&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=46128&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=46128&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=46128&r=mysqlcfg

Reply via email to