<?php
enum E: string { case A = 'a'; }
try {
$r = strip_tags(E::A);
} catch (Throwable $e) {
echo 'strip_tags ', get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
try {
htmlspecialchars(E::A);
} catch (Throwable $e) {
echo 'htmlspecialchars ', get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
Category
stdlibProblem
strip_tags()andhtmlspecialchars()reject non-strings withLogicException, not Zend’sTypeError. Backed enum cases must not be coerced via backing string (php-src-strict, same rule as #5780 / #5524).Blocked/partially masked by #5896 when the call is a void statement (
strip_tags(E::A);never validates).php-src reference
ext/standard/string.c—PHP_FUNCTION(strip_tags),PHP_FUNCTION(htmlspecialchars)(Z_PARAM_STR/zend_parse_parameters)Repro (add
test/repro-maintainer/parity_strip_tags_enum_typeerror.php)strip_tags(E::A)TypeError: … must be of type string, E givenLogicException: only supports strings…(or silent if #5896)htmlspecialchars(E::A)TypeErrorhtmlspecialchars.phpScope
ext/standard/strip_tags.php,htmlspecialchars.phpVmString::coerceStringBuiltinArg()/EnumCaseSupport::isEnumCaseVariable()— reject enum cases withTypeErrorext/standard/VmString.phplib/JIT/JitStringBuiltinArg.phpwhen loweredDone when
TypeErrormatching Zend message shape for enum case operandstest/compliance/cases/stdlib/strip_tags_enum_typeerror.phpt(and htmlspecialchars sibling) greenRelated