Skip to content

Language: include() does not mark path for include_once — Zend skips + true (Zend/zend_execute.c) #32101

Description

@PurHur

Category

Language · php-src-strict · include / include_once EG(included_files)

Problem

Zend records every successful include/require in EG(included_files). A later include_once/require_once of the same path must skip re-execution and return boolean true.

This compiler only calls Context::markCompileUnitLoaded() on the *_once opcodes. A prior plain include updates get_included_files() via recordIncludedFile() but does not set the once-guard, so the next include_once re-runs the file and returns its return value again.

include_once twice (no intervening plain include) already matches Zend — the once-table itself works.

Probed 2026-08-18 @ 03a5c7b939 — Zend 8.2.32 vs php bin/vm.php / php bin/jit.php.

Repro Zend 8.2.32 VM / JIT (2026-08-18)
file echo "RUN\n"; return 42; then include $f; include_once $f; RUN once, then 42 / true RUN twice, 42 / 42
include_once $g; include_once $g; (control) RUN2 once, 7 / true same (green)

php-src reference

  • php/php-src Zend/zend_execute.cZEND_INCLUDE_OR_EVAL, zend_hash_add_empty_element(&EG(included_files), …) on all successful includes; once kinds skip when the key exists and return true

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_include_once_return.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_include_once_return.php'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_include_once_return.php'

Snippet if the repro file is not in tree:

<?php
$f = '/tmp/phpc_once_ret.php';
file_put_contents($f, '<?php echo "RUN\n"; return 42;');
echo "include1="; var_export(include $f); echo "\n";
echo "include_once2="; var_export(include_once $f); echo "\n";

Done when

  • After a successful include/require, include_once/require_once of the same realpath does not re-execute and returns true (VM + JIT; AOT if in scope)
  • include_once twice (no prior plain include) still matches Zend
  • Compliance .phpt under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

Activity

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:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions