3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace NS { class C { public $fn; public function __construct() { $this->fn = function (string $arg) { var_dump("fn"); }; } } } namespace { $fn = (new NS\C)->fn; $fn("null"); echo "Done\n"; }
based on TD9s0
Output for 7.0.0 - 7.2.0
string(2) "fn" Done
Output for 5.4.2 - 5.6.28
Catchable fatal error: Argument 1 passed to NS\C::NS\{closure}() must be an instance of NS\string, string given, called in /in/6pNY6 on line 17 and defined in /in/6pNY6 on line 8
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/6pNY6 on line 16
Process exited with code 255.