Skip to content

Guard string functions against null input (PHP 8.1 deprecation)#40

Merged
TomK merged 1 commit into
masterfrom
fix-null-string-deprecations
Jun 17, 2026
Merged

Guard string functions against null input (PHP 8.1 deprecation)#40
TomK merged 1 commit into
masterfrom
fix-null-string-deprecations

Conversation

@TomK

@TomK TomK commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the PHP 8.1 deprecation warnings of the form:

strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated

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 (guards strtoupper/ucwords); constructor casts $name so _rawInput is never null (root fix; also guards preg_split in _splitWords).
  • AbstractPerson_isCompoundFragment() casts word/fragment before strtolower.
  • CVVHelper / AVSHelpergetCvv/getAvs cast $code before strtoupper.
  • CVVResponse / AVSResponse — constructors cast $code/$description.
  • LanguageHelpergetLanguage() casts $code before the str_replace/strtolower chain.

CountryHelper already guarded with is_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 -l clean on all 7 changed files.

🤖 Generated with Claude Code

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>
@TomK TomK merged commit ece57bf into master Jun 17, 2026
1 check passed
@TomK TomK deleted the fix-null-string-deprecations branch June 17, 2026 15:13
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.

2 participants