3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Aparent { protected $is_something; public function __construct() { $this->is_something = FALSE; $this->thing(); } public function thing() { if ($this->is_something) { print "Aparent.thing() reports is_something as TRUE\n"; } else { print "Aparent.thing() reports is_something as FALSE\n"; } } } class Achild extends Aparent { public function thing() { print "Achild before changing is_something\n"; if ($this->is_something) { print "Achild.thing() reports is_something as TRUE\n"; } else { print "Achild.thing() reports is_something as FALSE\n"; } $this->is_something = TRUE; print "Achild after changing is_something\n"; if ($this->is_something) { print "Achild.thing() reports is_something as TRUE\n"; } else { print "Achild.thing() reports is_something as FALSE\n"; } print "Achild calling parent::thing()\n"; parent::thing(); } } $o = new Achild();
Output for 5.0.0 - 7.1.0
Achild before changing is_something Achild.thing() reports is_something as FALSE Achild after changing is_something Achild.thing() reports is_something as TRUE Achild calling parent::thing() Aparent.thing() reports is_something as TRUE
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/csJTn on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/csJTn 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/csJTn on line 4
Process exited with code 255.