Repository navigation
Conversation
Several 5.x changes need an entry in the update guide. Creating the file once keeps them from conflicting over its creation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The API was untyped and used false as a sentinel for optional integer arguments (strpos() $offset, substr() $length). Add native parameter and return types, replace the sentinels with nullable integers, and document the changes, including the silent coercion of false/true to 0/1, in the 5.0 update guide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
The
StringHelperandNormaliseAPI is untyped, and optional integer arguments usefalseas a sentinel (strpos()$offset = false,substr()$length = false). This PR adds native parameter and return types to every public method of both classes and toStringHelper::$incrementStyles, and replaces the sentinels with nullable integers:strpos(string, string, ?int $offset = null): int|false,substr(string, int, ?int $length = null): string, andsubstr_replace(..., ?int $length = null).strcspn()/strspn()take?int $start/$length, andstrcspn()passes$start ?? 0tomb_substr().str_ireplace(string|array, string|array, string, ?int $count = null): string.strcmp()/strcasecmp()takestring|false $locale = false.ltrim()/rtrim()/trim()keepstring|false $charlist = false, because coercingfalseto''would silently disable trimming.ord(),strpos(),strrpos(),stristr()andtranscode()can returnfalse.strtolower(),strtoupper()andsubstr()returnstring.This is a breaking change. Without
strict_types, an explicitfalse/trueis coerced to0/1for the new?intparameters, which changes results silently (substr($s, 1, false)now returns''). The update guide lists these cases.Testing Instructions
The existing tests pass
nullinstead of thefalse/truesentinels (12 data rows inStringHelperTest). Otherwise the suite is unchanged and passes. phpcs is clean, and PHPStan reports no errors locally. The PHPStan job in CI fails on4.x-dev/5.x-devas well (mb_trimand the other PHP 8.4 polyfill functions are not found), and #66 fixes that on 4.x.Documentation Changes Required
docs/v4-to-v5-update.md: a section "Native parameter and return types" with the sentinel replacements and the coercion pitfalls.Depends on #84 (this branch is built on it, so its commit shows up here until #84 is merged). Related to #73, #75, #76, #77, #78, #79 and #81 on 4.x, which change bodies and docblocks of the same methods. Expect conflicts on the signature and docblock lines when 4.x-dev is merged into 5.x-dev. In particular, #73 rewrites the
$countdocblock ofstr_ireplace()(keep its wording with theinteger|nulltype here), and #77 rewritesstrcmp()/strcasecmp(). Related to #85 and #86, which also append todocs/v4-to-v5-update.md.🤖 Generated with Claude Code