3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class SomethingBuilder { private $name; private $super; function __construct($name){ $this->name = $name; } function setSuper($super){ $this->super = $super; } function getSuper(){ return $this->super; } function copy($whatToCopy = null, $copyOfwhatToCopy = null){ if($this !== $whatToCopy){ $copy = new SomethingBuilder($this->name); if($this->super) $copy->setSuper($this->super->copy( $whatToCopy ?? $this, $copyOfwhatToCopy ?? $copy )); return $copy; }else{ return $copyOfwhatToCopy; } } } echo "No circular dependency:\n"; $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $a->setSuper($b); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy()); echo "\n----------\n\n"; echo "Self circular dependency:\n"; $a = new SomethingBuilder("A"); $a->setSuper($a); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy()); echo "\n----------\n\n"; echo "Two items circular dependency:\n"; $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $b->setSuper($a); $a->setSuper($b); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy()); echo "\n----------\n\n"; echo "Three items circular dependency:\n"; $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $c = new SomethingBuilder("C"); $a->setSuper($c); $b->setSuper($a); $c->setSuper($b); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy());
Output for 7.0.0 - 7.2.0
No circular dependency: ORIGINAL: object(SomethingBuilder)#1 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#2 (2) { ["name":"SomethingBuilder":private]=> string(1) "B" ["super":"SomethingBuilder":private]=> NULL } } COPY: object(SomethingBuilder)#3 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#4 (2) { ["name":"SomethingBuilder":private]=> string(1) "B" ["super":"SomethingBuilder":private]=> NULL } } ---------- Self circular dependency: ORIGINAL: object(SomethingBuilder)#3 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> *RECURSION* } COPY: object(SomethingBuilder)#1 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> *RECURSION* } ---------- Two items circular dependency: ORIGINAL: object(SomethingBuilder)#4 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#5 (2) { ["name":"SomethingBuilder":private]=> string(1) "B" ["super":"SomethingBuilder":private]=> *RECURSION* } } COPY: object(SomethingBuilder)#2 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#6 (2) { ["name":"SomethingBuilder":private]=> string(1) "B" ["super":"SomethingBuilder":private]=> *RECURSION* } } ---------- Three items circular dependency: ORIGINAL: object(SomethingBuilder)#7 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#9 (2) { ["name":"SomethingBuilder":private]=> string(1) "C" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#8 (2) { ["name":"SomethingBuilder":private]=> string(1) "B" ["super":"SomethingBuilder":private]=> *RECURSION* } } } COPY: object(SomethingBuilder)#10 (2) { ["name":"SomethingBuilder":private]=> string(1) "A" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#11 (2) { ["name":"SomethingBuilder":private]=> string(1) "C" ["super":"SomethingBuilder":private]=> object(SomethingBuilder)#12 (2) { ["name":"SomethingBuilder":private]=> string(1) "B" ["super":"SomethingBuilder":private]=> *RECURSION* } } }
Output for 5.3.17 - 5.6.28
Parse error: syntax error, unexpected '?' in /in/fNHMA on line 25
Process exited with code 255.