Skip to content

Stdlib: strip_tags() — TypeError for non-string $string (ext/standard/string.c parity) #4593

Description

@PurHur

Category

stdlib

Problem

strip_tags() in Zend throws TypeError when $string is not a string. This compiler raises LogicException (strip_tags() only supports strings in this compiler build) on VM and JIT paths (ext/standard/strip_tags.php).

The second argument $allowed_tags must also throw TypeError when neither string nor null (Zend allows null).

php-src reference

Repro (failure today)

<?php
declare(strict_types=1);

function expect_type_error(callable $fn): void {
    try {
        $fn();
        echo "no throw\n";
    } catch (TypeError $e) {
        echo "TypeError\n";
    } catch (Throwable $e) {
        echo get_class($e), ':', $e->getMessage(), "\n";
    }
}

expect_type_error(fn () => strip_tags([]));
expect_type_error(fn () => strip_tags(new stdClass()));
expect_type_error(fn () => strip_tags(123));
expect_type_error(fn () => strip_tags('ok', []));
echo strip_tags('<b>x</b>'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_strip_tags_type.php
php bin/vm.php repro_strip_tags_type.php
php bin/jit.php repro_strip_tags_type.php
'
Call Zend PHP 8.x This compiler VM/JIT
strip_tags([]) TypeError LogicException
strip_tags(new stdClass()) TypeError LogicException
strip_tags(123) TypeError LogicException
strip_tags('ok', []) TypeError LogicException
strip_tags('<b>x</b>') x OK

Scope (this repo)

Module Path
VM ext/standard/strip_tags.php
JIT/AOT lib/JIT/Builtin/Type.php / __compiler_strip_tags in lib/AOT/runtime/
Tests test/repro-maintainer/parity_strip_tags_type.php, new test/compliance/cases/stdlib/strip_tags_type.phpt

Use shared TypeError throw helpers from other stdlib parity issues (#4578 wordwrap pattern).

Done when

  • All four invalid calls above throw TypeError on VM and JIT/AOT
  • Happy-path strip_tags('<b>x</b>') still prints x
  • ./script/ci-fast.sh --filter strip_tags green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter strip_tags'

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 machineimplementation-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