diff --git a/examples/error.php b/examples/error.php new file mode 100644 index 00000000..3bad2795 --- /dev/null +++ b/examples/error.php @@ -0,0 +1,7 @@ +fatalError($v, "The function `{$name}` is a built-in function and cannot be redefined"); } $functionDef = $this->parseFunctionDecl($v); + $functionDef->sourceFile = $this->file; + $functionDef->startLine = $v->getStartLine(); $this->addFunction($name, $functionDef); if ($this->methodDef) { $functionDef->method = true; diff --git a/src/Translator.php b/src/Translator.php index 4328fc01..a995c310 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -1161,11 +1161,16 @@ CODE; $code .= 'php_app_init();' . PHP_EOL; if ($this->isBuildModeBin()) { - if (count($this->functions[self::ENTRY_FUNCTION]->argInfoList) == 2) { - $code .= 'php::eval("global $argc, $argv; main($argc, $argv);");' . PHP_EOL; + $entryFunction = $this->functions[self::ENTRY_FUNCTION]; + $entryFile = $entryFunction->sourceFile; + $entryFileArg = $this->genCharPtr($entryFile, true); + $entryPrefix = str_repeat("\n", max(0, $entryFunction->startLine - 1)); + if (count($entryFunction->argInfoList) == 2) { + $entryScript = $entryPrefix . 'global $argc, $argv; main($argc, $argv);'; } else { - $code .= 'php::eval("main();");' . PHP_EOL; + $entryScript = $entryPrefix . 'main();'; } + $code .= 'php::eval(' . $this->genCharPtr($entryScript, true) . ', ' . $entryFileArg . ');' . PHP_EOL; } $code .= 'return SUCCESS;' . PHP_EOL; diff --git a/tests/aot/exception/main-file-location.phpt b/tests/aot/exception/main-file-location.phpt new file mode 100644 index 00000000..17a923c5 --- /dev/null +++ b/tests/aot/exception/main-file-location.phpt @@ -0,0 +1,21 @@ +--TEST-- +Uncaught AOT exception uses the PHP file containing main() +--FILE-- +fail(); +} +?> +--EXPECTF-- +Fatal error: Uncaught RuntimeException: location-test in %smain-file-location.php:10 +Stack trace: +%A