3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { protected static $a = 1; protected $b = 2; public function func() { echo 'foo' . static::$a . $this->b; } } class Bar extends Foo { protected static $a = 3; protected $b = 4; public function func() { echo 'bar' . static::$a . $this->b; } } $obj = new Bar(); $obj->func(); // Prints 'bar' $parentClassString = get_parent_class($obj); $newObj = new $parentClassString; // Gotta love PHP for magic like this $newObj->func(); // Prints 'foo'

preferences:
97.4 ms | 1921 KiB | 5 Q