3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $public_parent; protected $protected_parent; private $private_parent; public function whoami() { echo PHP_EOL, __METHOD__, PHP_EOL; echo 'self::class: ', self::class, PHP_EOL; echo 'static::class: ', static::class, PHP_EOL; echo 'property public_parent exists ? ', var_export(property_exists($this, 'public_parent'), true), PHP_EOL; echo 'property protected_parent exists ? ', var_export(property_exists($this, 'protected_parent'), true), PHP_EOL; echo 'property private_parent exists ? ', var_export(property_exists($this, 'private_parent'), true), PHP_EOL; echo 'property public_child exists ? ', var_export(property_exists($this, 'public_child'), true), PHP_EOL; echo 'property protected_child exists ? ', var_export(property_exists($this, 'protected_child'), true), PHP_EOL; echo 'property private_child exists ? ', var_export(property_exists($this, 'private_child'), true), PHP_EOL; echo 'property public_grandchild exists ? ', var_export(property_exists($this, 'public_grandchild'), true), PHP_EOL; echo 'property protected_grandchild exists ? ', var_export(property_exists($this, 'protected_grandchild'), true), PHP_EOL; echo 'property private_grandchild exists ? ', var_export(property_exists($this, 'private_grandchild'), true), PHP_EOL; } } class Foo_Child extends Foo { public $public_child; protected $protected_child; private $private_child; public function whoami() { echo PHP_EOL, __METHOD__, PHP_EOL; echo 'self::class: ', self::class, PHP_EOL; echo 'static::class: ', static::class, PHP_EOL; echo 'property public_parent exists ? ', var_export(property_exists($this, 'public_parent'), true), PHP_EOL; echo 'property protected_parent exists ? ', var_export(property_exists($this, 'protected_parent'), true), PHP_EOL; echo 'property private_parent exists ? ', var_export(property_exists($this, 'private_parent'), true), PHP_EOL; echo 'property public_child exists ? ', var_export(property_exists($this, 'public_child'), true), PHP_EOL; echo 'property protected_child exists ? ', var_export(property_exists($this, 'protected_child'), true), PHP_EOL; echo 'property private_child exists ? ', var_export(property_exists($this, 'private_child'), true), PHP_EOL; echo 'property public_grandchild exists ? ', var_export(property_exists($this, 'public_grandchild'), true), PHP_EOL; echo 'property protected_grandchild exists ? ', var_export(property_exists($this, 'protected_grandchild'), true), PHP_EOL; echo 'property private_grandchild exists ? ', var_export(property_exists($this, 'private_grandchild'), true), PHP_EOL; parent::whoami(); } } class Foo_GrandChild extends Foo_Child { public $public_grandchild; protected $protected_grandchild; private $private_grandchild; public function whoami() { echo PHP_EOL, __METHOD__, PHP_EOL; echo 'self::class: ', self::class, PHP_EOL; echo 'static::class: ', static::class, PHP_EOL; echo 'property public_parent exists ? ', var_export(property_exists($this, 'public_parent'), true), PHP_EOL; echo 'property protected_parent exists ? ', var_export(property_exists($this, 'protected_parent'), true), PHP_EOL; echo 'property private_parent exists ? ', var_export(property_exists($this, 'private_parent'), true), PHP_EOL; echo 'property public_child exists ? ', var_export(property_exists($this, 'public_child'), true), PHP_EOL; echo 'property protected_child exists ? ', var_export(property_exists($this, 'protected_child'), true), PHP_EOL; echo 'property private_child exists ? ', var_export(property_exists($this, 'private_child'), true), PHP_EOL; echo 'property public_grandchild exists ? ', var_export(property_exists($this, 'public_grandchild'), true), PHP_EOL; echo 'property protected_grandchild exists ? ', var_export(property_exists($this, 'protected_grandchild'), true), PHP_EOL; echo 'property private_grandchild exists ? ', var_export(property_exists($this, 'private_grandchild'), true), PHP_EOL; parent::whoami(); } } echo '==== GRANDCHILD OUTSIDE ====', PHP_EOL; $foo_grandchild = new Foo_GrandChild; echo 'property public_parent exists ? ', var_export(property_exists($foo_grandchild, 'public_parent'), true), PHP_EOL; echo 'property protected_parent exists ? ', var_export(property_exists($foo_grandchild, 'protected_parent'), true), PHP_EOL; echo 'property private_parent exists ? ', var_export(property_exists($foo_grandchild, 'private_parent'), true), PHP_EOL; echo 'property public_child exists ? ', var_export(property_exists($foo_grandchild, 'public_child'), true), PHP_EOL; echo 'property protected_child exists ? ', var_export(property_exists($foo_grandchild, 'protected_child'), true), PHP_EOL; echo 'property private_child exists ? ', var_export(property_exists($foo_grandchild, 'private_child'), true), PHP_EOL; echo 'property public_grandchild exists ? ', var_export(property_exists($foo_grandchild, 'public_grandchild'), true), PHP_EOL; echo 'property protected_grandchild exists ? ', var_export(property_exists($foo_grandchild, 'protected_grandchild'), true), PHP_EOL; echo 'property private_grandchild exists ? ', var_export(property_exists($foo_grandchild, 'private_grandchild'), true), PHP_EOL; echo PHP_EOL, '==== INSIDE GRANDCHILD ====', PHP_EOL; $foo_grandchild->whoami(); echo PHP_EOL, '==== CHILD OUTSIDE ====', PHP_EOL; $foo_child = new Foo_Child; echo 'property public_parent exists ? ', var_export(property_exists($foo_child, 'public_parent'), true), PHP_EOL; echo 'property protected_parent exists ? ', var_export(property_exists($foo_child, 'protected_parent'), true), PHP_EOL; echo 'property private_parent exists ? ', var_export(property_exists($foo_child, 'private_parent'), true), PHP_EOL; echo 'property public_child exists ? ', var_export(property_exists($foo_child, 'public_child'), true), PHP_EOL; echo 'property protected_child exists ? ', var_export(property_exists($foo_child, 'protected_child'), true), PHP_EOL; echo 'property private_child exists ? ', var_export(property_exists($foo_child, 'private_child'), true), PHP_EOL; echo 'property public_grandchild exists ? ', var_export(property_exists($foo_child, 'public_grandchild'), true), PHP_EOL; echo 'property protected_grandchild exists ? ', var_export(property_exists($foo_child, 'protected_grandchild'), true), PHP_EOL; echo 'property private_grandchild exists ? ', var_export(property_exists($foo_child, 'private_grandchild'), true), PHP_EOL; echo PHP_EOL, '==== INSIDE CHILD ====', PHP_EOL; $foo_child->whoami(); echo PHP_EOL, '==== PARENT OUTSIDE ====', PHP_EOL; $foo = new Foo; echo 'property public_parent exists ? ', var_export(property_exists($foo, 'public_parent'), true), PHP_EOL; echo 'property protected_parent exists ? ', var_export(property_exists($foo, 'protected_parent'), true), PHP_EOL; echo 'property private_parent exists ? ', var_export(property_exists($foo, 'private_parent'), true), PHP_EOL; echo 'property public_child exists ? ', var_export(property_exists($foo, 'public_child'), true), PHP_EOL; echo 'property protected_child exists ? ', var_export(property_exists($foo, 'protected_child'), true), PHP_EOL; echo 'property private_child exists ? ', var_export(property_exists($foo, 'private_child'), true), PHP_EOL; echo 'property public_grandchild exists ? ', var_export(property_exists($foo, 'public_grandchild'), true), PHP_EOL; echo 'property protected_grandchild exists ? ', var_export(property_exists($foo, 'protected_grandchild'), true), PHP_EOL; echo 'property private_grandchild exists ? ', var_export(property_exists($foo, 'private_grandchild'), true), PHP_EOL; echo PHP_EOL, '==== INSIDE PARENT ====', PHP_EOL; $foo->whoami();

preferences:
34.77 ms | 409 KiB | 5 Q