3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Base { public static $prop; } class Child extends Base { } // both values are A $expected = 'A'; Base::$prop = $expected; echo "Should be $expected and is " . Base::$prop . "\n"; echo "Should be $expected and is " . Child::$prop . "\n"; echo "\n"; // VALUES DIFFER $expected = 'B'; $property = new ReflectionProperty('Base', 'prop'); $property->setValue($expected); echo "Should be $expected and is " . Base::$prop . "\n"; echo "Should be $expected and is " . Child::$prop . "\n"; echo "\n"; // VALUES STILL DIFFER $expected = 'C'; Base::$prop = $expected; echo "Should be $expected and is " . Base::$prop . "\n"; echo "Should be $expected and is " . Child::$prop . "\n"; echo "\n";
Output for 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Should be A and is A Should be A and is A Deprecated: Calling ReflectionProperty::setValue() with a single argument is deprecated in /in/T43Sh on line 24 Should be B and is B Should be B and is B Should be C and is C Should be C and is C
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.1 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29
Should be A and is A Should be A and is A Should be B and is B Should be B and is B Should be C and is C Should be C and is C
Output for 7.0.0
Should be A and is A Should be A and is A Should be B and is B Should be B and is A Should be C and is C Should be C and is A

preferences:
145.71 ms | 408 KiB | 5 Q