Skip to content

require/include of a file that is not in the build silently returns false at run time (PHP: fatal error for require), and compile does not warn about it #545

Closed

Description

@lukas-kuna

What happened

  • At compile time: manticore compile main.php -o main succeeds (exit 0) when main.php does require_once __DIR__ . '/inc/lib.php' and inc/lib.php is 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_once returns false, the file's top-level code never runs, and the program continues;
    • a require of a path that does not exist at all does the same: it returns false with no warning;
    • PHP stops there with Failed opening required … (exit 255). For include it warns and continues.
  • 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_once with Error: Failed opening required …, and include/include_once with a warning. It should not return false silently.
  • At compile time: a warning or an error when a require/include whose 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.

Activity

  1. added
    bug
    wrong-answer
    area:runtime
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:runtimebugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions