<?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;
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.