3v4l.org

run code in 300+ PHP versions simultaneously
<?php spl_autoload_register(function($cname){ if ($cname == 'IMyInterface') { interface IMyInterface { // Use any class or interface constant as value of FOO. // I'll just use some constant available out of the box, to keep it simple: const FOO = FilesystemIterator::CURRENT_AS_PATHNAME; } } elseif ($cname == 'Foo') { class Foo implements IMyInterface {} } elseif ($cname == 'Bar') { class Bar extends Foo implements IMyInterface {} } }); // Foo is super-class for Bar. // uncomment below line to trigger the error: $F = new Foo(); // this should run without errors at any time, but if Foo is instantiated // prior to this line, then the error is triggered: $B = new Bar();

preferences:
25.66 ms | 404 KiB | 5 Q