Skip to content

Regression: substr_compare(..., null) $case_insensitive coerces — Zend TypeError (ext/standard/string.c) #29756

Description

@PurHur

Category

Regression · php-src-strict · bool param strictness · pillar 4

Problem

The optional fifth parameter $case_insensitive of substr_compare() is typed bool in php-src. Passing null must throw TypeError. VM/JIT call Variable::toBool() / JIT bool coercion and continue, returning a comparison result (0 in the probe).

This is distinct from haystack/needle soft-null on PROFILE≥8.4 (#21515, closed) — here all string/int operands are valid; only the bool argument is null.

Probed 2026-08-10 in php-compiler:22.04-dev (Zend 8.2.32, also verified under PHP_COMPILER_PROFILE=8.4).

Repro Zend 8.2 / 8.4 VM/JIT (2026-08-10)
substr_compare('abc','ab',0,2,null) TypeError: … $case_insensitive must be of type bool, null given int(0) (silent coerce) ❌

php-src reference

PHP implementation target

  • ext/standard/substr_compare.php — replace $ci->toBool() with strict bool check (mirror requireIntArg pattern for arg Stdlib: floatval, boolval, gettype(null) and expanded PHPT specs #5)
  • lib/JIT/Builtin/StringSubstrCompare.php / SubstrCompareJitHelper.php — emit TypeErrorRaise for non-bool $case_insensitive; remove LogicException “must be boolean in this compiler build” shortcut for boxed values

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/issue_substr_compare_null_ci.php'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/issue_substr_compare_null_ci.php'
./script/docker-exec.sh -- bash -lc 'php test/repro/issue_substr_compare_null_ci.php'

Done when

  • VM/JIT throw the same TypeError as Zend for null/non-bool $case_insensitive
  • Compliance .phpt guard 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