Skip to content

Language: static typed property with enum case default must compile (extends #9715, Zend/zend_compile.c) #9747

Description

@PurHur

Category

language · php-src-strict

Problem

#9715 tracks enum cases as defaults for parameters and instance properties. The same compile failure hits static typed properties:

enum G: string { case X = 'x'; }
class C { public static G $g = G::X; }

VM parse/compile fails: Cannot use string as default value for property C::$g of type G — enum case lowered to backing scalar during default validation.

Zend accepts the default and C::$g reads as an enum case object.

php-src reference

Repro (failure today)

Save as test/repro/maintainer_gap_static_enum_default.php:

<?php
declare(strict_types=1);

enum G: string { case X = 'x'; }

class C {
    public static G $g = G::X;
}

echo C::$g->name, "\n";
php test/repro/maintainer_gap_static_enum_default.php
# Zend: x

./script/docker-exec.sh php bin/vm.php test/repro/maintainer_gap_static_enum_default.php
# VM: compile error — Cannot use string as default value...

Scope

Path Work
lib/Compiler.php treat enum case defaults like other constant expressions for static properties
lib/VM.php static property default materialization preserves enum case objects
Same fix as #9715 share one code path for param / instance / static defaults

Done when

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 18, 2026
  2. PurHur commented on Jun 18, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jun 18, 2026

    @PurHur
    OwnerAuthor

    Already fixed on master: issue repro + enum_property_default.phpt + maintainer parity repros all green. Pivoting worker to #9714.

  4. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  5. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    Merged via #9958.

    Static typed property enum defaults were already green on master (shared path with #9715 / enum_property_default.phpt). This PR completes the issue checklist:

    • Maintainer repro: test/repro/maintainer_gap_static_enum_default.php
    • Unit: VmEnumDefaultParameterTest::testBackedEnumStaticPropertyDefaultIsCaseSingleton

    Verification (VM prints X + enum singleton identity):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro/maintainer_gap_static_enum_default.php
    php bin/vm.php test/compliance/cases/language/enum_property_default.phpt
    vendor/bin/phpunit test/unit/VmEnumDefaultParameterTest.php
    '
  6. added a commit that references this issue on Jun 19, 2026
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: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