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();
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 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 CHILD ==== 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
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/0keTN on line 10
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/0keTN on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/0keTN on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/0keTN on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/0keTN on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/0keTN on line 4
Process exited with code 255.

preferences:
382.29 ms | 401 KiB | 468 Q