Conversation
zonuexe
marked this pull request as draft
September 14, 2026 11:27
Override phpstorm-stubs' #[Pure(true)] classification so mb_str_pad() is handled like comparable mbstring string-processing functions. This enables pure-function checks, unused-result diagnostics, and repeated-call narrowing without changing BetterReflection fallback metadata handling. Co-authored-by: Cursor <cursoragent@cursor.com>
zonuexe
force-pushed
the
align-mbstring-string-function-purity
branch
from
September 14, 2026 12:33
f1bac43 to
0483215
Compare
mb_str_pad() as side-effect-free like other mbstring string functions
zonuexe
marked this pull request as ready for review
September 14, 2026 13:05
Collaborator
|
This pull request has been marked as ready for review. |
Contributor
|
I sent a comment into phpstorm stubs, as the inconsistency for |
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.
Among the mbstring string-processing functions in the issue's reproducer, phpstorm-stubs marks
mb_str_pad()as#[Pure(true)], while comparable functions such asmb_strlen(),mb_strcut(), andmb_trim()are marked#[Pure]. The metadata generator therefore emitshasSideEffects => trueformb_str_padonly, so@phpstan-purefunctions cannot call it.This change treats
mb_str_padashasSideEffects => falseso it matches those siblings.This is a pragmatic override, not a claim that the function is theoretically pure. The result can change if the analysed program changes internal encoding (
mb_internal_encoding()ordefault_charset). PHPStan does not track encoding-state changes made by the analysed program. Some existing return-type extensions (mb_strlen()andmb_str_split()) use the analyser process'smb_internal_encoding()when the encoding argument is omitted;mb_str_pad()itself has no dedicated return-type extension. Encoding-dependent purity (explicit encoding = pure, omitted = impure) remains out of scope.This is not the same rationale as the
ob_get_level()exception in #6439: PHPStan models output-buffer level changes, but it does not model the encoding state that affectsmb_str_pad(). This override is an explicit consistency trade-off, not a scope-managed-state optimization.functionMetadata_original.phprecords this project-specific policy, while the generator special case prevents phpstorm-stubs' current#[Pure(true)]annotation from rejecting or reversing it during regeneration.Applying
functionMetadataon BetterReflection's fallback path is not done here: name-keyed built-in metadata can leak to user polyfills and unrelated built-ins. This PR does not change the pre-existing cross-version discovery of PHP 8.4-only mbstring names underphpVersion: 8.3.Addresses Issue 1 in phpstan/phpstan#15224. Issue 2 (encoding-sensitive purity) remains open and is not addressed by this PR.
Made with Cursor