Skip to content

Language: declare(strict_types=1) folds define() user constants at compile time — Undefined constant fatal (zend_compile.c) #17678

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

Under declare(strict_types=1);, bareword references to user constants registered via define() later in the same file are resolved at compile time and fatal with Undefined constant before define() executes. Zend resolves these names at runtime after define() runs.

Repro Zend 8.2+ VM (2026-07-10)
declare(strict_types=1); define('MY_SCALAR',42); var_export(MY_SCALAR,true); 42 Fatal error: Undefined constant "MY_SCALAR"
Same without strict_types 42 42

php-src reference

PHP implementation target

  • lib/ compile path — do not treat in-file define() targets as compile-time constants when emitting bareword fetches under strict_types
  • VM/JIT shared constant resolution (ConstantExpr, FetchConst lowering)

Repro

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

Done when

  • test/repro/maintainer_gap_define_runtime_constant_strict.php prints ok on VM/JIT/AOT
  • Compliance guard under test/compliance/cases/language/define_runtime_constant_strict.phpt
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    enhancementNew feature or request
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 10, 2026
  2. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — starting this run

  3. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #17686

    Verification

    ./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_define_runtime_constant_strict.php'
    # 42 / ok
    
    ./script/docker-exec.sh -- bash -lc 'php vendor/bin/phpunit --filter define_runtime_constant_strict'
    # OK (2 tests) — VM + JIT compliance

    Fix: statement-level define() no longer mis-wired as a var_export inline producer; hoisted ConstFetch preludes fold prescan'd define constants and preserve runtime registration order.

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 / JITenhancementNew feature or requestimplementation-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