3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Obj { public function __construct($mix) { foreach ($mix as $k => $v) { $this->$k = $v; } } public function __toString() { $str = ''; foreach ($this as $k => $v) { $str = "$k => $v\n"; } return $str; } } class A { public $obj; public function setObj($obj) { $this->obj = $obj; } public function getObj() { return $this->obj; } function __sleep() { return ['test' => $this->obj]; } } function printA(A $a) { var_dump($a); serialize(debug_backtrace(0)); } $obj = new Obj(['hello'=>'there']); $a = new A(); $a->setObj($obj); var_dump($a->getObj()); printA($a); var_dump($a->getObj());
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Deprecated: Creation of dynamic property Obj::$hello is deprecated in /in/hN9eJ on line 6 object(Obj)#1 (1) { ["hello"]=> string(5) "there" } object(A)#2 (1) { ["obj"]=> object(Obj)#1 (1) { ["hello"]=> string(5) "there" } } Warning: serialize(): A::__sleep() should return an array only containing the names of instance-variables to serialize in /in/hN9eJ on line 39 Warning: serialize(): "hello => there " returned as member variable from __sleep() but does not exist in /in/hN9eJ on line 39 object(Obj)#1 (1) { ["hello"]=> string(5) "there" }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
object(Obj)#1 (1) { ["hello"]=> string(5) "there" } object(A)#2 (1) { ["obj"]=> object(Obj)#1 (1) { ["hello"]=> string(5) "there" } } Warning: serialize(): A::__sleep() should return an array only containing the names of instance-variables to serialize in /in/hN9eJ on line 39 Warning: serialize(): "hello => there " returned as member variable from __sleep() but does not exist in /in/hN9eJ on line 39 object(Obj)#1 (1) { ["hello"]=> string(5) "there" }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
object(Obj)#1 (1) { ["hello"]=> string(5) "there" } object(A)#2 (1) { ["obj"]=> object(Obj)#1 (1) { ["hello"]=> string(5) "there" } } Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize. in /in/hN9eJ on line 39 Notice: serialize(): "hello => there " returned as member variable from __sleep() but does not exist in /in/hN9eJ on line 39 object(Obj)#1 (1) { ["hello"]=> string(5) "there" }
Output for 7.3.32 - 7.3.33
object(Obj)#1 (1) { ["hello"]=> string(5) "there" } object(A)#2 (1) { ["obj"]=> object(Obj)#1 (1) { ["hello"]=> string(5) "there" } } object(Obj)#1 (1) { ["hello"]=> string(5) "there" }
Output for 5.6.8 - 5.6.28
object(Obj)#1 (1) { ["hello"]=> string(5) "there" } object(A)#2 (1) { ["obj"]=> object(Obj)#1 (1) { ["hello"]=> string(5) "there" } } Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize. in /in/hN9eJ on line 39 Notice: serialize(): "hello => there " returned as member variable from __sleep() but does not exist in /in/hN9eJ on line 39 string(15) "hello => there "
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35
object(Obj)#1 (1) { ["hello"]=> string(5) "there" } object(A)#2 (1) { ["obj"]=> object(Obj)#1 (1) { ["hello"]=> string(5) "there" } } Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize. in /in/hN9eJ on line 39 object(Obj)#1 (1) { ["hello"]=> string(5) "there" }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/hN9eJ on line 32
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/hN9eJ on line 32
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/hN9eJ on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/hN9eJ 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/hN9eJ on line 4
Process exited with code 255.

preferences:
135.97 ms | 422 KiB | 5 Q