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), '------');

preferences:
24.36 ms | 404 KiB | 5 Q