Guard string functions against null input (PHP 8.1 deprecation)#40
Merged
Conversation
Passing null to strtoupper/strtolower/str_replace/preg_split etc. is deprecated as of PHP 8.1. Cast nullable runtime inputs to string at the entry points so empty-code/empty-name handling continues to work: - Person: null-safe _smartUcWords; cast constructor name (also guards preg_split in _splitWords) - AbstractPerson: cast word/fragment in _isCompoundFragment - CVVHelper/AVSHelper + CVVResponse/AVSResponse: cast code/description - LanguageHelper: cast code before the str_replace/strtolower chain Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bajb
approved these changes
Jun 17, 2026
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
Fixes the PHP 8.1 deprecation warnings of the form:
triggered when nullable runtime values (PSP-supplied codes, person names) reach string functions. Each affected entry point now casts to string —
(string) null === '', which the existing empty-code / empty-name handling already covers correctly.Changes
Person—_smartUcWords()returns''on null (guardsstrtoupper/ucwords); constructor casts$nameso_rawInputis never null (root fix; also guardspreg_splitin_splitWords).AbstractPerson—_isCompoundFragment()casts word/fragment beforestrtolower.CVVHelper/AVSHelper—getCvv/getAvscast$codebeforestrtoupper.CVVResponse/AVSResponse— constructors cast$code/$description.LanguageHelper—getLanguage()casts$codebefore thestr_replace/strtolowerchain.CountryHelperalready guarded withis_string(), so it was left unchanged. Build scripts under*/build/were skipped — dev-only tooling, not runtime paths.Test plan
vendor/bin/phpunit— 107/107 pass (1 pre-existing risky no-assertion test, unrelated).php -lclean on all 7 changed files.🤖 Generated with Claude Code