3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ThatRebinds { public function worksWith(Closure $callback): void { $callback->call($this); } private function methodAvailableToCallback(): void { echo __METHOD__; } } class ThatSupplies { public function __construct() { $object = new ThatRebinds(); $object->worksWith(function() { // and it can call $this->methodAvailableToCallback(); }); } } new ThatSupplies;
Output for 7.1.0 - 7.1.33, 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.4, 8.3.6 - 8.3.7
ThatRebinds::methodAvailableToCallback
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 ThatRebinds::methodAvailableToCallback
Output for 7.0.0 - 7.0.33
ThatRebinds::methodAvailableToCallback Fatal error: Uncaught TypeError: Return value of ThatRebinds::methodAvailableToCallback() must be an instance of void, none returned in /in/jdq1o:8 Stack trace: #0 /in/jdq1o(16): ThatRebinds->methodAvailableToCallback() #1 [internal function]: ThatRebinds->{closure}() #2 /in/jdq1o(4): Closure->call(Object(ThatRebinds)) #3 /in/jdq1o(17): ThatRebinds->worksWith(Object(Closure)) #4 /in/jdq1o(20): ThatSupplies->__construct() #5 {main} thrown in /in/jdq1o on line 8
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/jdq1o on line 3
Process exited with code 255.

preferences:
220.45 ms | 401 KiB | 288 Q