Req #45375 [Opn->Csd]: __object_vars() magic method
| From: | aharvey@php.net | Date: | Thu, 16 Sep 2010 14:03:16 +0000 |
| Subject: | Req #45375 [Opn->Csd]: __object_vars() magic method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154426@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=45375&edit=1
ID: 45375
Updated by: aharvey@php.net
Reported by: margus dot sipria at gmail dot com
Summary: __object_vars() magic method
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: JSON related
Operating System: *
PHP Version: 5.2.6
-Assigned To:
+Assigned To: aharvey
Block user comment: N
New Comment:
Trunk now has the JsonSerializable interface which implements equivalent
functionality, just with a slightly different API.
Previous Comments:
------------------------------------------------------------------------
[2008-06-27 09:15:30] margus dot sipria at gmail dot com
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 this bug report at http://bugs.php.net/bug.php?id=45375&edit=1