Skip to content

Language: instance typed property enum case default must compile (extends #9747, re-#9715, Zend/zend_compile.c) #9954

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

Zend allows enum cases as default values for instance typed properties:

class P {
    public E $e = E::A;
}

Closed #9715 tracked parameter + property defaults; #9747 covers static typed properties only. Instance property defaults still fail at compile:

Cannot use int as default value for property $e of type E

because enum cases are lowered to backing scalars during default materialization.

php-src reference

Repro

<?php
declare(strict_types=1);

enum E: int { case A = 1; }

function f(E $e = E::A): void {
    echo $e->name, "\n";
}

class P {
    public E $e = E::A;
}

f();
$p = new P();
echo $p->e->name, "\n";
./script/docker-exec.sh php bin/vm.php test/repro-maintainer/enum_default_parameter_property.php
# Today: parseAndCompile failure on property default (parameter path may also fail — see #9730)
# Zend: prints A twice

Scope (this repo)

Path Work
lib/Compiler.php Property default materialization preserves enum case objects
lib/VM.php Instance property init from enum case default
lib/JIT/Builtin/Type/Object_.php Default property slots store enum case handles
Tests New test/compliance/cases/language/enum_instance_property_default.phpt

Done when (php-src-strict)

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

    @PurHur
    OwnerAuthor

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

  3. PurHur commented on Jun 20, 2026

    @PurHur
    OwnerAuthor

    Verified on master 2026-06-20: repro + enum_default_param_property.phpt green on VM. Already fixed — unclaiming, no PR needed.

  4. PurHur commented on Jun 23, 2026

    @PurHur
    OwnerAuthor

    Closing as stale: repro green on master 2026-06-23 (lane A queue audit — prior claim/unclaim comments confirmed; issue left open).

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