Skip to content

Regression: property hooks + explicit backing — spurious Cannot redeclare when sibling property sits between hook and backing (re-#9673, Zend/zend_compile.c) #16936

Closed

Description

@PurHur

Category

language · property hooks · php-src-strict

Problem

Valid PHP 8.4 classes with a hooked property, an unrelated sibling property, and an explicit private backing field for the hook compile on Zend but fail here with Cannot redeclare C::$x.

Repro Zend 8.4 VM (2026-07-06)
hooked $x + public string $y + private int $x backing compiles; $c->x works parseAndCompile failure: Cannot redeclare C::$x
hooked $x + private int $x only (no sibling) compiles compiles (A ok)

Discovered via maintainer VM scan (test/repro/maintainer_gap_property_hook_multi_property_redeclare.php). Regression of #9673 — closed 2026-06-18 but repro red again on master with PHP_COMPILER_PROFILE=8.4.

php-src reference

PHP implementation target

  • lib/Compiler.php / property-hook decl collector — do not treat explicit backing $x as a duplicate symbol when a sibling property is declared between the hook and backing field
  • Parser/lowering only; no runtime/*.c expansion

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && export PHP_COMPILER_PROFILE=8.4 && php bin/vm.php test/repro/maintainer_gap_property_hook_multi_property_redeclare.php'
# parseAndCompile failure: Cannot redeclare C::$x

Minimal inline repro:

class C {
    public int $x { get => $this->x; set => $this->x = $value; }
    public string $y = 'a';
    private int $x = 1;
}

Done when

  • maintainer_gap_property_hook_multi_property_redeclare.php prints compile-ok x=1 y=a
  • Compliance .phpt under test/compliance/cases/language/property_hooks/
  • php-src-strict; VM/JIT/AOT agree

Activity

  1. added
    bugSomething isn't working
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 6, 2026
  2. PurHur commented on Jul 6, 2026

    @PurHur
    OwnerAuthor

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

  3. PurHur commented on Jul 6, 2026

    @PurHur
    OwnerAuthor

    Merged via #16941.

    Fix: PropertyHooks preprocessor merges detached same-name backing fields (initializer folded into hooked property decl; backing field removed from class body) so sibling properties between hook and backing no longer trigger spurious Cannot redeclare.

    Verification:

    PHP_COMPILER_PROFILE=8.4 php bin/vm.php test/repro/maintainer_gap_property_hook_multi_property_redeclare.php
    → compile-ok x=1 y=a
    
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 workingenhancementNew 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