Category
language · php-src-strict
Problem
Casting a backed enum case to int with (int) must emit E_WARNING: Object of class E could not be converted to int and still yield the backing value. VM today returns 1 silently (no warning, no error_get_last() entry).
Related coercion gaps: #8974 (settype), #9001 (strval must Error). This issue is specifically the (int) cast operator on enum objects.
php-src reference
Repro
test/repro/maintainer_gap_enum_int_cast_warning.php:
<?php
enum E: int { case A = 1; }
set_error_handler(static fn (): bool => true);
var_export((int) E::A);
echo "\n";
var_export(error_get_last()['message'] ?? 'no warning');
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_enum_int_cast_warning.php
./script/docker-exec.sh -- php test/repro/maintainer_gap_enum_int_cast_warning.php
| Engine |
Value |
Warning |
| Zend |
1 |
Object of class E could not be converted to int |
| VM today |
1 |
no warning |
Scope (this repo)
lib/VM.php cast handler / TypeCheck — enum branch before silent scalar extraction
- Shared guards: align with
VmString::coerceStringBuiltinArg-style centralization if a cast helper exists
- JIT: mirror via same PHP helper when
(int) on enum is compiled
Done when
Related
Category
language· php-src-strictProblem
Casting a backed enum case to
intwith(int)must emitE_WARNING: Object of class E could not be converted to intand still yield the backing value. VM today returns1silently (no warning, noerror_get_last()entry).Related coercion gaps: #8974 (
settype), #9001 (strvalmust Error). This issue is specifically the(int)cast operator on enum objects.php-src reference
Zend/zend_operators.c—cast_object/ int castZend/zend_enum.c— enum object cast rulesRepro
test/repro/maintainer_gap_enum_int_cast_warning.php:1Object of class E could not be converted to int1no warningScope (this repo)
lib/VM.phpcast handler /TypeCheck— enum branch before silent scalar extractionVmString::coerceStringBuiltinArg-style centralization if a cast helper exists(int)on enum is compiledDone when
test/compliance/cases/language/enum_int_cast_warning.phpt./script/ci-fast.sh --filter enum_int_cast_warninggreenRelated