3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); ini_set('display_errors', true); class A { private $func = null; public function __construct($func) { $this->func = $func; } public function exec() { $this->func(); } } $a = new A(function() { echo 'works'; }); $a->exec();
based on bJkS2
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method A::func() in /in/Auho0:14 Stack trace: #0 /in/Auho0(22): A->exec() #1 {main} thrown in /in/Auho0 on line 14
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Fatal error: Call to undefined method A::func() in /in/Auho0 on line 14
Process exited with code 255.