3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Main implements \JsonSerializable { private $objA=[], $objB=[]; public function start() { for ($i = 0; $i < 10; $i++) { $objB=$this->getObjBandAddToStack($i); $this->objA[]=new ClassA($objB); } } private function getObjBandAddToStack($i) { if(isset($this->objB[$i/2])) { $objB=$this->objB[$i/2]; } else { $objB=new ClassB(); $this->objB[$i]=$objB; } return $objB; } public function jsonSerialize(){ return [ 'objA' => $this->objA, 'objB' => $this->objB, ]; } } class ClassA implements \JsonSerializable { private $objB; public function __construct(ClassB $objB) { $this->objB=$objB; $objB->joinGroup($this); } public function jsonSerialize(){ return [ 'objB' => $this->objB, ]; } } class ClassB implements \JsonSerializable { private $objAgroup=[]; public function joinGroup($objA) { $this->objAgroup[]=$objA; } public function jsonSerialize(){ return [ 'objAgroup' => $this->objAgroup, ]; } } $main=new Main(); $main->start(); var_dump(json_encode($main)); var_dump(json_last_error()); var_dump(json_last_error_msg());
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Main::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/B6LVu on line 25 Deprecated: Return type of ClassA::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/B6LVu on line 42 Deprecated: Return type of ClassB::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/B6LVu on line 57 Deprecated: Implicit conversion from float 0.5 to int loses precision in /in/B6LVu on line 15 Deprecated: Implicit conversion from float 0.5 to int loses precision in /in/B6LVu on line 16 Deprecated: Implicit conversion from float 1.5 to int loses precision in /in/B6LVu on line 15 Deprecated: Implicit conversion from float 2.5 to int loses precision in /in/B6LVu on line 15 Deprecated: Implicit conversion from float 2.5 to int loses precision in /in/B6LVu on line 16 Deprecated: Implicit conversion from float 3.5 to int loses precision in /in/B6LVu on line 15 Deprecated: Implicit conversion from float 3.5 to int loses precision in /in/B6LVu on line 16 Deprecated: Implicit conversion from float 4.5 to int loses precision in /in/B6LVu on line 15 bool(false) int(6) string(18) "Recursion detected"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
34.17 ms | 410 KiB | 5 Q