Category
stdlib | php-src-strict
Problem
settype($var, 'int') (and other scalar targets) on a backed enum case variable silently coerces to the backing value in this compiler. Zend emits Warning: Object of class E could not be converted to int before applying the conversion — observable via error handlers and error_reporting.
The VM path uses EnumCaseSupport::tryCastToInt() in ext/standard/VmSettype.php without surfacing the php-src warning.
php-src reference
Repro (verified 2026-06-16)
test/repro-maintainer/parity_settype_enum_warning.php:
<?php
declare(strict_types=1);
enum E: int { case A = 1; }
$e = E::A;
settype($e, 'int');
var_export($e);
echo "\n";
./script/docker-exec.sh -- bash -lc 'php test/repro-maintainer/parity_settype_enum_warning.php 2>&1'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro-maintainer/parity_settype_enum_warning.php 2>&1'
| Runtime |
Output |
| Zend PHP 8.2 |
Warning: Object of class E could not be converted to int then 1 |
| VM (today) |
1 (no warning) ❌ |
Scope (PHP-in-PHP)
| Layer |
Path |
| VM |
ext/standard/VmSettype.php, ext/standard/VmScalarType.php — emit E_WARNING via VM error API before enum backing coercion |
| JIT |
ext/standard/JitSettype.php — match warning + result |
| Tests |
test/compliance/cases/stdlib/settype_enum_warning.phpt |
Implement in ext/standard/ — no new runtime/*.c coercion tables.
Done when
Related
Category
stdlib| php-src-strictProblem
settype($var, 'int')(and other scalar targets) on a backed enum case variable silently coerces to the backing value in this compiler. Zend emitsWarning: Object of class E could not be converted to intbefore applying the conversion — observable via error handlers anderror_reporting.The VM path uses
EnumCaseSupport::tryCastToInt()inext/standard/VmSettype.phpwithout surfacing the php-src warning.php-src reference
ext/standard/type.c—php_settype,zend_convert_to_longobject branchZend/zend_operators.c— object-to-scalar conversion warningsRepro (verified 2026-06-16)
test/repro-maintainer/parity_settype_enum_warning.php:Warning: Object of class E could not be converted to intthen11(no warning) ❌Scope (PHP-in-PHP)
ext/standard/VmSettype.php,ext/standard/VmScalarType.php— emit E_WARNING via VM error API before enum backing coercionext/standard/JitSettype.php— match warning + resulttest/compliance/cases/stdlib/settype_enum_warning.phptImplement in
ext/standard/— no newruntime/*.ccoercion tables.Done when
settype($e, 'object')on enum still preserves enum object (existing behavior)./script/ci-fast.sh --filter settype_enum_warninggreenRelated