From: margus dot sipria at gmail dot com Operating system: * PHP version: 5.2.6 PHP Bug Type: Feature/Change Request Bug description: __object_vars() magic method
Description: ------------ When I use __set and __get methods on object i have set data to my object, and when i wanna get thows methods i would only get public methods that are non. Same think is happened when i wanna example transfere Object to json format, there should be some way that i could get data that i wanna. This could be very useful example using with Zend Framwork encoding a Database Table Row (http://framework.zend.com/manual/en/zend.db.table.row.html) where data is in private variable. if not a Core function (that it should be in my opinion) then SPL interface would be needed. Reproduce code: --------------- class Test { protected $_data = array(); public function __set($var, $value) {$this->_data[$var] = $value;} public function __get($var) { if (isset($this->_data[$var])) {return $this->_data[$var]; } trigger_error('Undefined property: ' . __CLASS__ . '::$' . $var, E_USER_NOTICE); return null; } public function __isset($var) {return isset($this->_data[$var]);} public function __object_vars() { return $this->_data; } } $json = new Test(); $json->variable = 'value'; echo json_encode($json); Expected result: ---------------- {"variable":"value"} Actual result: -------------- {} -- Edit bug report at http://bugs.php.net/?id=45375&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45375&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45375&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45375&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45375&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45375&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45375&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45375&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45375&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45375&r=support Expected behavior: http://bugs.php.net/fix.php?id=45375&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45375&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45375&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45375&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45375&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45375&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45375&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45375&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45375&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45375&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45375&r=mysqlcfg