Skip to content

Stdlib: strtok() — TypeError for non-string operands (ext/standard/string.c parity, phase 2 of #3201) #4587

Description

@PurHur

Category

stdlib

Problem

#3201 (closed) registered strtok() with continuation state (ext/standard/strtok.php, VmString::strtok). Invalid operand types still throw LogicException instead of Zend TypeError, and JIT must not segfault on bad types.

Same pattern as #4551#4581 string TypeError sweep.

php-src reference

Repro

<?php
foreach ([[123, ','], [ 'a,b,c', 456 ]] as [$s, $tok]) {
    try {
        strtok($s, $tok);
    } catch (Throwable $e) {
        echo get_class($e), ': ', substr($e->getMessage(), 0, 60), "...\n";
    }
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Runtime Result
Zend TypeError for argument #1 and #2 with must be of type string
VM today LogicException: strtok() argument #N must be a string in this compiler build

Happy path unchanged:

<?php
$s = 'a,b,c';
echo strtok($s, ','), ' ', strtok(','), ' ', strtok(','), "\n";
// a b c

Scope (this repo)

Layer Path
VM ext/standard/strtok.php, ext/standard/VmString.php
JIT ext/standard/JitStrtok.php / StringStrtok — TypeError + no segfault
Tests test/compliance/cases/stdlib/strtok_type_error.phpt

Done when

  • TypeError repro matches Zend messages on VM
  • JIT repro: bad types → TypeError; good types → a b c line
  • ./script/ci-fast.sh --filter strtok_type green

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:compilerCompiler / CFG / JITarea: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