3v4l.org

run code in 300+ PHP versions simultaneously
<?php $base = sys_get_temp_dir() . '/gh10232-base'; if (!is_dir($base)) { mkdir($base) or die; } $files = [ 'gh10232.php' => <<<'END' <?php set_include_path('gh10232-nonexistent') or exit(1); chdir(__DIR__) or exit(1); spl_autoload_register(function () { trigger_error(__LINE__); $ex = new Exception(); echo 'Exception on line ', $ex->getLine(), "\n"; require_once __DIR__ . '/gh10232/constant_def.inc'; }, true); class ConstantRef { public const VALUE = ConstantDef::VALUE; } ConstantRef::VALUE; END, 'gh10232/constant_def.inc' => <<<'END' <?php trigger_error(basename(__FILE__)); $ex = new Exception(); echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n"; require_once 'required.inc'; // The script of the same directory. class ConstantDef { const VALUE = true; } END, 'gh10232/required.inc' => <<<'END' <?php trigger_error(basename(__FILE__)); $ex = new Exception(); echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n"; END, ]; foreach ($files as $path => $content) { $path = $base . '/' . $path; if (!is_dir(dirname($path))) { mkdir(dirname($path)); } file_put_contents($path, $content); } require_once $base . '/' . (function_exists('array_key_first') ? array_key_first($files) : key($files));

preferences:
33.91 ms | 411 KiB | 5 Q