Skip to content

Regression: substr_compare(..., null) $offset TypeError — Zend DEP+coerce (ext/standard/string.c) #29504

Description

@PurHur

Category

stdlib · php-src-strict · null→int DEP · pillar 4

Problem

substr_compare($haystack, $needle, null) must emit E_DEPRECATED for passing null to int $offset, coerce to 0, and return the comparison result. VM/JIT throw TypeError: … Argument #3 ($offset) must be of type int, null given with no deprecation.

Probed 2026-08-09 @ dd181e4f49 vs container Zend 8.2.32. VM and JIT agree (both wrong).

Repro Zend 8.2+ VM / JIT
substr_compare('abc', 'b', null) DEP then -1 TypeError on $offset

php-src reference

PHP implementation target

  • ext/standard substr_compare / shared int-arg null DEP+coerce helper (same pattern as siblings for strspn/strcspn/range null args)
  • PHP-in-PHP; no new runtime/*.c logic

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/substr_compare_null.php <<\"PHP\"
<?php
error_reporting(E_ALL);
set_error_handler(static function (int $no, string $str): bool {
    echo \"WARN: $str\n\";
    return true;
});
try {
    var_export(substr_compare(\"abc\", \"b\", null));
    echo \"\n\";
} catch (Throwable $e) {
    echo get_class($e), \": \", $e->getMessage(), \"\n\";
}
PHP
php /tmp/substr_compare_null.php; php bin/vm.php /tmp/substr_compare_null.php; php bin/jit.php /tmp/substr_compare_null.php'

Done when

  • VM + JIT: null $offset → DEP + coerce to 0 + same return as Zend
  • Compliance .phpt under test/compliance/cases/stdlib/
  • php-src-strict; no php-compiler-strict shortcut

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 machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions