3v4l.org

run code in 300+ PHP versions simultaneously
<?php class x { private $p = 'secret'; function RetVal(){ return $this->p; } } class y { private $q = 'queen'; function RetValue() { return $this->q; } } $f = function() { return (new x)->RetVal(); }; echo $f(),"\n"; $g = function(){ return $this->p; }; $nu = $g->bindto((new x), "x"); echo $nu(),"\n"; echo $g->call((new x)); $ff = function() use(&$g) { return $g(); }; echo $ff->call((new y));
Output for 7.0.0 - 7.0.20, 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.19, 8.3.0 - 8.3.7
secret secret secret Fatal error: Uncaught Error: Using $this when not in object context in /in/3qVQ2:21 Stack trace: #0 /in/3qVQ2(28): {closure}() #1 [internal function]: y->{closure}() #2 /in/3qVQ2(30): Closure->call(Object(y)) #3 {main} thrown in /in/3qVQ2 on line 21
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
secret secret Fatal error: Call to undefined method Closure::call() in /in/3qVQ2 on line 25
Process exited with code 255.

preferences:
174.08 ms | 402 KiB | 214 Q