3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { public $classB, $classC; public function __construct(){ // Do stuff that should only be initialized once // Then later : $this -> classB = new B(); $this -> classC = new C(); } } Class B { public function __construct(){ } public function sayHi() { echo 'hi'; } } Class C extends A { public function __construct() { $this -> classB -> sayHi(); } } $test = new A();
Output for 7.0.0 - 7.3.0rc4
Fatal error: Uncaught Error: Call to a member function sayHi() on null in /in/SVBNm:25 Stack trace: #0 /in/SVBNm(9): C->__construct() #1 /in/SVBNm(29): A->__construct() #2 {main} thrown in /in/SVBNm on line 25
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Fatal error: Call to a member function sayHi() on null in /in/SVBNm on line 25
Process exited with code 255.
Output for 5.0.0 - 5.5.38
Fatal error: Call to a member function sayHi() on a non-object in /in/SVBNm on line 25
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/SVBNm on line 3
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/SVBNm on line 3
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/SVBNm on line 3
Process exited with code 255.