note 111064 added to function.var-export

From: Date: Thu, 10 Jan 2013 22:32:58 +0000
Subject: note 111064 added to function.var-export
Groups: php.notes 
Request: Send a blank email to php-notes+get-192893@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.199 Probable Submitter: 2.224.21.46 ---- Manual Page -- http://php.net/manual/en/function.var-export.php Edit -- https://master.php.net/note/edit/111064 Del: integrated -- https://master.php.net/note/delete/111064/integrated Del: useless -- https://master.php.net/note/delete/111064/useless Del: bad code -- https://master.php.net/note/delete/111064/bad+code Del: spam -- https://master.php.net/note/delete/111064/spam Del: non-english -- https://master.php.net/note/delete/111064/non-english Del: in docs -- https://master.php.net/note/delete/111064/in+docs Del: other reasons-- https://master.php.net/note/delete/111064 Reject -- https://master.php.net/note/reject/111064 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192893) next »