Skip to content

Fix PHP 8.1+ deprecation warnings for null parameters#755

Open
marcing wants to merge 1 commit intoitsgoingd:masterfrom
marcing:fix/php-8.x-deprecations
Open

Fix PHP 8.1+ deprecation warnings for null parameters#755
marcing wants to merge 1 commit intoitsgoingd:masterfrom
marcing:fix/php-8.x-deprecations

Conversation

@marcing
Copy link

@marcing marcing commented Mar 8, 2026

Summary

PHP 8.1 deprecated passing null to non-nullable string parameters of internal functions. These deprecations become TypeError in PHP 9.0.

This PR adds null coalescing (?? '' / ?? null) to all call sites where null can reach internal string/array functions:

  • Support/Vanilla/Clockwork.php$_SERVER['REQUEST_METHOD'], REQUEST_URI, HTTP_HOST, SERVER_NAME, SERVER_ADDR are undefined in CLI context, causing warnings in explode() and downstream consumers
  • Request/IncomingRequest.php$this->host can be null, passed to explode()
  • Request/ShouldCollect.php$request->uri passed to preg_match(), $request->method passed to strtoupper()
  • Request/Request.php$query['query'] passed to ltrim() in all 5 database query counter methods
  • DataSource/PhpDataSource.php$host passed to trim() when falsy but not strictly null-checked
  • DataSource/LumenDataSource.php$_POST['_method'] passed to strtoupper(), $_SERVER['REQUEST_URI'] passed to str_replace()
  • DataSource/EloquentDataSource.php$query['query'] passed to ltrim()
  • Helpers/StackFilter.php — nullable StackFrame properties (class, file, function, vendor) passed to in_array()

Test plan

  • Verify no PHP deprecation warnings when Clockwork is used in CLI context (e.g. artisan commands, queue workers)
  • Verify normal web request profiling still works correctly
  • Run existing test suite

🤖 Generated with Claude Code

…ctions

PHP 8.1 deprecated passing null to non-nullable string parameters of
internal functions (strtoupper, explode, preg_match, ltrim, trim, in_array,
str_replace, etc). This will become a TypeError in PHP 9.0.

Fixed files:
- Support/Vanilla/Clockwork.php: $_SERVER keys missing in CLI context
- Request/IncomingRequest.php: null host passed to explode()
- Request/ShouldCollect.php: null uri/method passed to preg_match/strtoupper
- Request/Request.php: null query passed to ltrim in database query counters
- DataSource/PhpDataSource.php: null host passed to trim
- DataSource/LumenDataSource.php: null $_SERVER/$_POST values
- DataSource/EloquentDataSource.php: null query passed to ltrim
- Helpers/StackFilter.php: null frame properties passed to in_array

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant