Skip to content

Language: property hooks in interfaces — concrete property must satisfy interface { get; } (PHP 8.4, zend_compile.c) #7311

@PurHur

Description

@PurHur

Category

language

Problem

PHP 8.4 allows property hooks in interface declarations, e.g. public string $label { get; }. A implementing class may satisfy the get hook with an ordinary typed property (public string $label = 'hi';) without declaring an explicit hook body.

This compiler parses the interface, but rejects valid implementations:

Class C contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (C::$label::get)

php-src reference

Repro (failure today)

<?php
interface I {
    public string $label { get; }
}
class C implements I {
    public string $label = 'hi';
}
$c = new C();
echo $c->label, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php repro.php
# Compare on PHP 8.4+ reference build when available
'

Observed (VM): compile-time abstract-method fatal for C::$label::get.

Expected (php-src 8.4): compiles; prints hi.

Implementation hints (PHP-in-PHP)

  • Teach interface/class compatibility in compiler + PHPCfg: a concrete typed property with matching visibility/type satisfies an interface { get; } (and { set; } where applicable) without an explicit hook body.
  • Align with existing property hook lowering in lib/SourcePreprocessor/PropertyHooks.php and VM dispatch in lib/VM.php.
  • Compliance: test/compliance/cases/language/interface_property_hooks.phpt.

Pairs

Done when

  • Repro compiles on VM and prints hi (no abstract-method fatal for C::$label::get)
  • Class that omits the property or declares incompatible type/hook still compile-fatals with php-src-aligned message
  • Interface with { get; set; } and implementing class with matching typed property + implicit hooks still works
  • ./script/ci-fast.sh --filter interface_property_hooks green
  • No new C runtime branches

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter interface_property_hooks'
php bin/vm.php test/repro/maintainer_interface_property_hooks.php
php bin/vm.php test/repro/maintainer-interface_property_hooks.php 2>/dev/null || true

Strictness

php-src-strict — default CI/compliance must match PHP 8.4 Zend interface hook satisfaction rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: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 features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions