note 111064 deleted from function.var-export by aharvey
| From: | aharvey@php.net | Date: | Fri, 11 Jan 2013 00:26:02 +0000 |
| Subject: | note 111064 deleted from function.var-export by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192899@lists.php.net to get a copy of this message | ||
Note Submitter: destefano dot flavio at gmail dot com
----
How to export an object complete structure, including private variable, using the
"var_export" feature.
// the function
function â«($o)
{
ob_start();
var_export($o);
$class_regex = "[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*";
$code = preg_replace("#".$class_regex."::__set_state#", 'return',
ob_get_clean());
return eval($code.';');
}
// example
class A
{
private $var = '1';
private $arr = array(1,2,3,array('a','b'));
};
$a = new A();
$object = â«($a);
var_dump( $object["var"] ); // note that "arr" is private