3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $prot; public $pub; } function dehydrate($obj){ $class = get_class($obj); $exp = var_export($obj,1); return eval('return '.substr($exp,strpos($exp,'(')+1,-1).';'); } function hydrate($class,$dry=null){ static $hydrators = array(); $h = '_Hydrator__'.$class; if (empty($hydrators[$class])) { eval('class '.$h.' extends '.$class.' { static function __hydrate(array $array) { $o = new '.$class.'(); foreach ($array as $prop_name => $prop_value) $o->$prop_name = $prop_value; return $o; } } '); $hydrators[$class] = true; } return $dry?$h::__hydrate($dry):null; } //hydrate('Foo'); var_dump( hydrate('Foo',array('prot'=>1,'pub'=>2)) );
Output for git.master, git.master_jit, rfc.property-hooks
object(Foo)#1 (2) { ["prot":protected]=> int(1) ["pub"]=> int(2) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
35.12 ms | 401 KiB | 8 Q