Skip to content

Instantly share code, notes, and snippets.

@kopiro
Last active December 10, 2015 22:59
Show Gist options
  • Select an option

  • Save kopiro/4506417 to your computer and use it in GitHub Desktop.

Select an option

Save kopiro/4506417 to your computer and use it in GitHub Desktop.
Export all properties, including private/protected/public of an object.
<?php
/* The function */
function ∫($o)
{
$class_regex = "[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*";
$code = preg_replace("#{$class_regex}::__set_state#", 'return', var_export($o,1));
return eval($code.';');
}
/* end function */
class A
{
private $var = '1';
private $arr = array(1, 2, 3, array('a','b', array(1,3));
public $pubvar = 3;
};
$a = new A();
$object = ∫($a);
var_dump($object);
var_dump($object["arr"]);
// note that "arr" is private.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment