Skip to content

Stdlib: substr_compare(null $offset) DEP+coerce like Z_PARAM_LONG (#29504) - #29520

Merged
PurHur merged 1 commit into
masterfrom
fix/29504-substr-compare-null-offset
Aug 9, 2026
Merged

Stdlib: substr_compare(null $offset) DEP+coerce like Z_PARAM_LONG (#29504)#29520
PurHur merged 1 commit into
masterfrom
fix/29504-substr-compare-null-offset

Conversation

@PurHur

@PurHur PurHur commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • substr_compare(..., null) $offset now emits Zend-shaped E_DEPRECATED and coerces to 0 (php-src ext/standard/string.c Z_PARAM_LONG), instead of a hard TypeError.
  • VM uses VmMath::parseChrCodepointForFrame; JIT/AOT uses JitChr::lowerZParamLongArg + compile-time soft-null fold (same helpers as substr_count #21657).
  • Compliance/AOT guards + dedicated SubstrCompareNullOffset{VM,JIT}Test; typeerror fixtures use non-numeric 'x' so numeric-string coerce matches Zend.

Closes #29504

php-src reference

  • ext/standard/string.cPHP_FUNCTION(substr_compare)
  • ext/standard/string.stub.phpint $offset

Test plan

  • php bin/vm.php test/repro/issue_29504_substr_compare_null_offset.phpWARN[8192]: … parameter #3 ($offset)… + -1
  • php bin/jit.php test/repro/issue_29504_substr_compare_null_offset.php → same
  • ./phpc build -o /tmp/sc29504 test/repro/issue_29504_substr_compare_null_offset_aot.php && /tmp/sc29504 → DEP + -1
  • vendor/bin/phpunit --filter SubstrCompareNullOffset → OK (2 tests)
  • vendor/bin/phpunit test/compliance/SubstrCompareVMTest.php / SubstrCompareJITTest.php → OK

Pillar probe: user_release_ready: yes (inventory/spine/north-star5-fast green); gen-0 seed noted stale (unrelated).

Made with Cursor

…9504)

Route $offset through shared soft-null int helpers (VmMath/JitChr) so null
matches php-src deprecate+coerce instead of a hard TypeError.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 5416dbb into master Aug 9, 2026
1 check failed
@PurHur
PurHur deleted the fix/29504-substr-compare-null-offset branch August 9, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant