Skip to content

Stdlib: strip_tags()/htmlspecialchars() enum case operands must TypeError (ext/standard/string.c, php-src-strict) #5897

Description

@PurHur

Category

stdlib

Problem

strip_tags() and htmlspecialchars() reject non-strings with LogicException, not Zend’s TypeError. 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

Repro (add test/repro-maintainer/parity_strip_tags_enum_typeerror.php)

<?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;
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php8.2 test/repro-maintainer/parity_strip_tags_enum_typeerror.php
php bin/vm.php test/repro-maintainer/parity_strip_tags_enum_typeerror.php'
Builtin Zend VM today
strip_tags(E::A) TypeError: … must be of type string, E given LogicException: only supports strings… (or silent if #5896)
htmlspecialchars(E::A) TypeError same pattern in htmlspecialchars.php

Scope

Path Work
ext/standard/strip_tags.php, htmlspecialchars.php VmString::coerceStringBuiltinArg() / EnumCaseSupport::isEnumCaseVariable() — reject enum cases with TypeError
ext/standard/VmString.php Shared guard (PHP-in-PHP)
JIT Mirror in lib/JIT/JitStringBuiltinArg.php when lowered

Done when

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