Skip to content

Language: match() enum-case subject must not match scalar int arms via backing coercion (Zend/zend_execute.c) #9716

Description

@PurHur

Category

language · php-src-strict

Problem

Inverse of #9566 (scalar subject vs enum arm). When the match subject is an enum case object, arms labeled with backing scalars must not match via coercion.

Zend uses strict identity; match (F::X) { 1 => 'int_hit', F::X => 'case_hit' } returns case_hit.

This compiler coerces the subject to int and returns int_hit.

php-src reference

Repro (failure today)

<?php
declare(strict_types=1);

enum F: int { case X = 1; }

echo match (F::X) {
    1 => 'int_hit',
    F::X => 'case_hit',
    default => 'miss',
}, "\n";
./script/docker-exec.sh php bin/vm.php test/repro-maintainer/match_enum_subject_scalar_arm.php
php test/repro-maintainer/match_enum_subject_scalar_arm.php
Engine Output
Zend PHP 8.2+ case_hit
This compiler VM int_hit

Scope

Done when

Related

Activity

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