3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'blah1' => 1, 'blah2' => 2, 'blah3' => 3 ); class Blah { public static $blah1 = 4; protected static $blah2 = 5; private static $blah3 = 6; } $rc = new ReflectionClass('Blah'); // brand new ReflectionClass var_dump($rc); $static = $rc->getProperties(ReflectionProperty::IS_STATIC); $obj = $rc->newInstanceWithoutConstructor(); foreach($static as $prop){ if(!empty($arr[$prop->getName()])){ $prop->setAccessible(true); $prop->setValue($obj, $arr[$prop->getName()]); //$rc->setStaticPropertyValue($prop->getName(), $arr[$prop->getName()]); } } $obj2 = $rc->newInstanceWithoutConstructor(); // instantiate class after ReflectionClass has set all property values var_dump($obj2); var_dump($obj2::$blah1); // class instantiated before ReflectionClass captured ReflectionClass values // but after we have called "setValue" var_dump($obj); var_dump($obj::$blah1);
Output for git.master, git.master_jit, rfc.property-hooks
object(ReflectionClass)#1 (1) { ["name"]=> string(4) "Blah" } object(Blah)#6 (0) { } int(1) object(Blah)#5 (0) { } int(1)

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:
48.79 ms | 401 KiB | 8 Q