Skip to content

include followed by include_once of the same file runs it twice #407

Closed as not planned

Description

@blacktrs

Summary

include followed by include_once of the same file runs it twice.

Repro

<?php
$f = sys_get_temp_dir() . '/mc_inc_once_' . getmypid() . '.php';
file_put_contents($f, '<?php echo "ran\n";');
include $f;
include_once $f;
unlink($f);

Expected (php)

ran

Actual (manticore 57b5de57, Darwin arm64)


Tracking

Known-bug repro: tests/aot/repro/wrong/include_once_after_include_runs_twice.php — bash tests/aot/xfail.sh -k include_once_after_include_runs_twice reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 23, 2026
  2. blacktrs commented on Oct 24, 2026

    @blacktrs
    ContributorAuthor

    Findings from a first fix attempt (not a small bug):

    • The parser lowers all four include forms to __mc_require_value and drops the _once distinction.
    • At top level, an include of a file that is a compile unit is a no-op because its code already ran when the binary started. Inside functions, a file that is not a compile unit is inlined at every include site (LowerExprs::lowerScopedInclude), so include followed by include_once of the same file runs it twice. Confirmed with a file that exists at build time.
    • get_included_files() is hard-coded to the entry script.
    • The repro in tests/aot/repro/wrong/include_once_after_include_runs_twice.php writes the included file at run time with an echo in it; a native binary has no interpreter, so it prints nothing at all (only pure-data return files are evaluated for runtime-written files). That repro cannot pass in any native implementation and should be rewritten around a build-time file.

    A fix needs the _once flag carried from Parser.php into lowering, a per-file "included" guard on the scoped inline, and a real get_included_files().

  3. blacktrs commented on Oct 24, 2026

    @blacktrs
    ContributorAuthor

    Closing: the repro cannot work in an AOT binary. A file written at run time is never evaluated as PHP, so its echo never runs. Static include/require/include_once are inlined once at build time and the double run was not reproduced there. Reopen with a repro that uses a static file if it still shows up.

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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions