From: Operating system: n/a PHP version: Irrelevant Package: Class/Object related Bug Type: Feature/Change Request Bug description:magic __toArray() for objects
Description: ------------ It would be nice to have an analogous method to __toString() for arrays.. maybe __toArray() for customized array return. Test script: --------------- class myObject { private $data1; private $data2; private $meta1; public function __construct($data1, $data2) { $this->data1 = $data1; $this->data2 = $data2; $this->meta1 = strlen($data1) + strlen($data2); } public function __toArray() { return array('data1'=>$this->data1, 'data2'=>$this->data2); } } $obj = new myObject('test', 'script'); var_dump($obj); Expected result: ---------------- array('data1'=>'test', 'data2'=> 'script') Actual result: -------------- Not implemented -- Edit bug report at http://bugs.php.net/bug.php?id=52807&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52807&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52807&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52807&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52807&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52807&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52807&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52807&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52807&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52807&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52807&r=support Expected behavior: http://bugs.php.net/fix.php?id=52807&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52807&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52807&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52807&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52807&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52807&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52807&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52807&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52807&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52807&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52807&r=mysqlcfg