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 GRANDCHILD ====', 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();
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
==== GRANDCHILD OUTSIDE ==== property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? false property public_child exists ? true property protected_child exists ? true property private_child exists ? false property public_grandchild exists ? true property protected_grandchild exists ? true property private_grandchild exists ? true ==== INSIDE GRANDCHILD ==== Foo_GrandChild::whoami self::class: Foo_GrandChild static::class: Foo_GrandChild property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? false property public_child exists ? true property protected_child exists ? true property private_child exists ? false property public_grandchild exists ? true property protected_grandchild exists ? true property private_grandchild exists ? true Foo_Child::whoami self::class: Foo_Child static::class: Foo_GrandChild property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? false property public_child exists ? true property protected_child exists ? true property private_child exists ? true property public_grandchild exists ? true property protected_grandchild exists ? true property private_grandchild exists ? true Foo::whoami self::class: Foo static::class: Foo_GrandChild property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? true property public_child exists ? true property protected_child exists ? true property private_child exists ? false property public_grandchild exists ? true property protected_grandchild exists ? true property private_grandchild exists ? true ==== CHILD OUTSIDE ==== property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? false property public_child exists ? true property protected_child exists ? true property private_child exists ? true property public_grandchild exists ? false property protected_grandchild exists ? false property private_grandchild exists ? false ==== INSIDE GRANDCHILD ==== Foo_Child::whoami self::class: Foo_Child static::class: Foo_Child property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? false property public_child exists ? true property protected_child exists ? true property private_child exists ? true property public_grandchild exists ? false property protected_grandchild exists ? false property private_grandchild exists ? false Foo::whoami self::class: Foo static::class: Foo_Child property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? true property public_child exists ? true property protected_child exists ? true property private_child exists ? true property public_grandchild exists ? false property protected_grandchild exists ? false property private_grandchild exists ? false ==== PARENT OUTSIDE ==== property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? true property public_child exists ? false property protected_child exists ? false property private_child exists ? false property public_grandchild exists ? false property protected_grandchild exists ? false property private_grandchild exists ? false ==== INSIDE PARENT ==== Foo::whoami self::class: Foo static::class: Foo property public_parent exists ? true property protected_parent exists ? true property private_parent exists ? true property public_child exists ? false property protected_child exists ? false property private_child exists ? false property public_grandchild exists ? false property protected_grandchild exists ? false property private_grandchild exists ? false

preferences:
140.07 ms | 410 KiB | 121 Q