Skip to content

Stdlib: settype() on enum cases — must emit Warning before int coercion (ext/standard/type.c, php-src-strict) #8974

Description

@PurHur

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

  • VM emits Warning matching Zend substring before coercing enum case to int/float/string targets
  • settype($e, 'object') on enum still preserves enum object (existing behavior)
  • ./script/ci-fast.sh --filter settype_enum_warning green
  • php-src-strict: VM/JIT agree

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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions