Skip to content

Language: property hook duplicate backing property names must fail compile (Zend/zend_compile.c) #10393

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

PHP 8.4 property hooks declare a public hooked property and a private backing field with the same name inside one class. Zend rejects duplicate property declarations at compile time.

This compiler accepts the pattern and runs:

class C {
    public int $x { get => $this->x; set => $this->x = $value; }
    public string $y = 'a';
    private int $x = 1; // duplicate name — must be compile error
}

VM today prints compile-ok x=1 y=a; Zend must not compile.

php-src reference

Repro

test/repro/maintainer_gap_property_hook_multi_property_redeclare.php:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_property_hook_multi_property_redeclare.php 2>&1 | tail -2
php bin/vm.php test/repro/maintainer_gap_property_hook_multi_property_redeclare.php 2>&1 | tail -2
'
Runtime Result
Zend PHP 8.4+ compile error (duplicate property $x)
VM today compile-ok x=1 y=a ❌

Scope (PHP-in-PHP)

Path Work
lib/Compiler.php after hook lowering, detect duplicate property names in CE
lib/SourcePreprocessor/PropertyHooks.php align backing name rules with zend_compile
Tests test/compliance/cases/language/property_hook_duplicate_name.phpt

Done when (php-src-strict)

  • Repro fails compile on VM with Zend-matching message
  • Valid hook + distinct backing patterns from php-src tests still compile
  • ./script/ci-fast.sh --filter property_hook_duplicate green

Related

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 20, 2026
  2. PurHur commented on Jun 21, 2026

    @PurHur
    OwnerAuthor

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

  3. PurHur commented on Jun 21, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-b — implementing detached same-name backing compile gate (#10393)

  4. PurHur commented on Jun 21, 2026

    @PurHur
    OwnerAuthor

    Merged via #10420.

    Fix: Removed detached same-name backing field merge in PropertyHooks (#9673/#9831). Only immediately-adjacent backing fields still merge (#7031). Detached private $x after other properties now hits compiler Cannot redeclare C::$x matching zend_compile.c.

    Verification:

    php bin/vm.php test/repro/maintainer_gap_property_hook_multi_property_redeclare.php
    # parseAndCompile failure: Cannot redeclare C::$x (exit 255)
    
    ./vendor/bin/phpunit test/compliance/ --filter property_hook_duplicate_name
    # OK
    
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

    IMPORTANTCritical patharea:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions