Repository navigation
Closed
Labels
area:runtimeRuntime: shutdown, traces, collectorbugSomething isn't workingwrong-answerCompiles and runs, output differs from php
Description
What happened
- At compile time:
manticore compile main.php -o mainsucceeds (exit 0) whenmain.phpdoesrequire_once __DIR__ . '/inc/lib.php'andinc/lib.phpis not in the compile set. The only hint is a trap note for a function from that file. The include path is a constant expression. - At run time:
- the
require_oncereturnsfalse, the file's top-level code never runs, and the program continues; - a
requireof a path that does not exist at all does the same: it returnsfalsewith no warning; - PHP stops there with
Failed opening required …(exit 255). Forincludeit warns and continues.
- the
- What the user sees: the program fails later, at the first use of a class from the file. A file with only top-level code (configuration, registration) is skipped without any message.
Steps to reproduce
<?php
// inc/lib.php
echo "lib.php runs\n";
final class Foo { public function hi(): string { return "hi from Foo"; } }
function bar(): string { return "bar"; }<?php
// main.php
var_dump(require_once __DIR__ . '/inc/lib.php');
var_dump(include __DIR__ . '/inc/missing.php');
var_dump(require __DIR__ . '/inc/missing.php');
echo "still running\n";
echo (new Foo())->hi(), " ", bar(), "\n";$ manticore compile main.php -o main; echo "exit $?"
build: undefined-function traps (1): bar
exit 0
$ ./main; echo "exit $?"
bool(false)
bool(false)
bool(false)
still running
PHP Fatal error: Uncaught Error: Class "Foo" not found
exit 255
$ php -n main.php
lib.php runs
int(1)
Warning: include(…/inc/missing.php): Failed to open stream: No such file or directory in …/main.php on line 3
Warning: include(): Failed opening '…/inc/missing.php' for inclusion …
bool(false)
Warning: require(…/inc/missing.php): Failed to open stream: No such file or directory in …/main.php on line 4
Fatal error: Uncaught Error: Failed opening required '…/inc/missing.php' …
Listing the file (manticore compile main.php inc/lib.php -o main) works. manticore analyze main.php prints No errors found. for the program above.
docs/differences.md lists "include / require with a path held in a variable (checked with a file written at run time)" among the things that work. A file written by the program itself and then included through a variable returns false and does not run:
<?php
$f = __DIR__ . '/written-at-run-time.php';
var_dump(file_put_contents($f, "<?php echo \"dyn runs\\n\"; return 42;"), file_exists($f));
var_dump(include $f); // php: "dyn runs", int(42); Manticore: bool(false)
unlink($f);Expected
- At run time: a target that is not part of the build fails as in PHP:
require/require_oncewithError: Failed opening required …, andinclude/include_oncewith a warning. It should not returnfalsesilently. - At compile time: a warning or an error when a
require/includewhose path the compiler can evaluate (__DIR__ . '/…', a literal) names a file outside the compile set.
The undefined class itself (Foo is reported only at run time, analyze finds nothing) is covered by #489.
Environment
Manticore 0.17.0 (release tarball manticore-0.17.0-linux-amd64) and main at 3b44bdea built with bin/build (same output); clang 19.1.7; Debian 13, Linux 6.12, x86-64; PHP 8.2.34 for comparison.
Metadata
Metadata
Assignees
Labels
area:runtimeRuntime: shutdown, traces, collectorbugSomething isn't workingwrong-answerCompiles and runs, output differs from php
Activity