Skip to content

Language: BackedEnum::from() invalid value — ValueError not 'Method call on non-object' (Zend/zend_enum.c) #9889

Description

@PurHur

Category

language | php-src-strict

Problem

BackedEnum::from($invalid) must throw ValueError: {value} is not a valid backing value for enum {Enum}. The VM emits Method call on non-object instead — wrong exception and message; likely enum case/scalar confusion in static enum method dispatch.

php-src reference

Repro

test/repro/enum_from_invalid.php:

<?php
enum E: int { case A = 1; }
try {
    E::from(99);
} catch (Throwable $e) {
    echo get_class($e) . ': ' . $e->getMessage();
}
echo "\n";
source script/php-env.sh
php test/repro/enum_from_invalid.php
php bin/vm.php test/repro/enum_from_invalid.php
Call Zend VM today
E::from(99) ValueError: 99 is not a valid backing value for enum E Method call on non-object
E::tryFrom(99) null verify same dispatch path

Scope (PHP-in-PHP)

Layer Path
VM BackedEnum::from / tryFrom builtins under enum static dispatch
Shared lib/VM/EnumCaseSupport.php — preserve enum class entry for static calls
Tests test/compliance/cases/language/backed_enum_from_value_error.phpt

Done when (php-src-strict)

Related

#9876 · #9846 · #9847 · #9730 · #1492

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

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