3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Orig {} class Override1 {} class Override2 {} class Override3 {} class A { function g () { global $prop, $instance; $newProp = ['override1']; $newInstance = new Override1; $prop=$newProp; $instance=$newInstance; } function ap ($prop, $instance) { $newProp = ['override2']; $newInstance = new Override2; $prop=$newProp; $instance=$newInstance; } function al (&$prop, &$instance) { $newProp = ['override3']; $newInstance = new Override3; $prop=$newProp; $instance=$newInstance; } } $prop = ['orig']; $instance = new Orig; var_dump('Orig:', $prop[0], get_class($instance), '------'); $prop = ['orig']; $instance = new Orig; (new A)->g(); var_dump('As global:', $prop[0], get_class($instance), '------'); $prop = ['orig']; $instance = new Orig; (new A)->ap($prop, $instance); var_dump('As arg:', $prop[0], get_class($instance), '------'); $prop = ['orig']; $instance = new Orig; (new A)->al($prop, $instance); var_dump('As link arg:', $prop[0], get_class($instance), '------');
Output for 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.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
string(5) "Orig:" string(4) "orig" string(4) "Orig" string(6) "------" string(10) "As global:" string(9) "override1" string(9) "Override1" string(6) "------" string(7) "As arg:" string(4) "orig" string(4) "Orig" string(6) "------" string(12) "As link arg:" string(9) "override3" string(9) "Override3" string(6) "------"

preferences:
47.86 ms | 408 KiB | 5 Q