3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function foo(): Closure { $b = new B(); return function() use ($b) { $b->bar(); }; } } ?> <?php use Biz\ImportedException; class B { public function bar() { throw new ImportedException(); } } ?> <?php namespace Biz; use \Exception; class ImportedException extends Exception { } ?> <?php $a = new A(); $closure = $a->foo(); $closure(); ?>
Output for 7.1.0 - 7.1.17, 7.2.0 - 7.2.6
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /in/d1TDf on line 25
Process exited with code 255.

preferences:
168.51 ms | 1395 KiB | 32 Q