3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { function __construct($fun) { $fun(); } function callMe() { echo "yay\n"; } static function create($fun) { return new X($fun); } } $x = null; $x = X::create(function() use ($x) { $x->callMe(); });
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to a member function callMe() on null in /in/1KgtR:9 Stack trace: #0 /in/1KgtR(4): {closure}() #1 /in/1KgtR(6): X->__construct(Object(Closure)) #2 /in/1KgtR(9): X::create(Object(Closure)) #3 {main} thrown in /in/1KgtR on line 9
Process exited with code 255.
Output for 5.6.0 - 5.6.38
Fatal error: Call to a member function callMe() on null in /in/1KgtR on line 9
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
Fatal error: Call to a member function callMe() on a non-object in /in/1KgtR on line 9
Process exited with code 255.

preferences:
250.94 ms | 402 KiB | 339 Q