3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Header { public function __construct() { $this->project = get_prior_object(); $this->modules = get_prior_object(1); } } class Modules { public function __construct() { $this->project = get_prior_object(); $this->header = new Header(); } } class Project { public $config = "config"; public function __construct() { $this->modules = new Modules(); } } $p = new Project(); var_dump($p->modules, $p->modules->header, $p->modules->project); function get_prior_object($skip = 0) { $bt = debug_backtrace(); if (isset($bt[1]['function']) && $bt[1]['function'] === "__construct") { // called from constructor, so skip it! $skip++; } foreach ($bt as $stack) { if (isset($stack['function']) && $stack['function'] === "__construct" && $skip-- <= 0) { return $stack['object']; } } return null; }
Output for 5.2.14 - 5.2.17, 5.3.3 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } } } object(Header)#3 (2) { ["project"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> *RECURSION* } ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> *RECURSION* ["header"]=> *RECURSION* } } } object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> *RECURSION* ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> *RECURSION* } } }
Output for 5.1.1 - 5.2.13, 5.3.0 - 5.3.2
object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } } } } ["header"]=> object(Header)#3 (2) { ["project"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } } } ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } } } } } } object(Header)#3 (2) { ["project"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } } } } ["header"]=> object(Header)#3 (2) { ["project"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> *RECURSION* } ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> *RECURSION* } } } } ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> *RECURSION* ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> *RECURSION* } } } ["header"]=> object(Header)#3 (2) { ["project"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> *RECURSION* } ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> *RECURSION* ["header"]=> *RECURSION* } } } } } } object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> *RECURSION* ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> *RECURSION* } } } ["header"]=> object(Header)#3 (2) { ["project"]=> object(Modules)#2 (2) { ["project"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> *RECURSION* } } } ["modules"]=> object(Project)#1 (2) { ["config"]=> string(6) "config" ["modules"]=> object(Modules)#2 (2) { ["project"]=> *RECURSION* ["header"]=> object(Header)#3 (2) { ["project"]=> *RECURSION* ["modules"]=> *RECURSION* } } } } } }
Output for 5.0.0 - 5.1.0
Notice: Undefined index: object in /in/lOjkA on line 43 Notice: Undefined index: object in /in/lOjkA on line 43 Notice: Undefined index: object in /in/lOjkA on line 43 object(Modules)#2 (2) { ["project"]=> NULL ["header"]=> object(Header)#3 (2) { ["project"]=> NULL ["modules"]=> NULL } } object(Header)#3 (2) { ["project"]=> NULL ["modules"]=> NULL } NULL
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/lOjkA on line 5
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/lOjkA on line 5
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/lOjkA on line 5
Process exited with code 255.