All jobs

Fix "Passing null to parameter of type string is deprecated" on PHP 8.1 and later

Yes. An agent finds the call that receives null, guards it the way the code handles bad input already, runs the tests and linter, and opens a pull request.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts from the line the deprecation names. In a tracing client like jonahgeorge/jaeger-client-php, issue #133 quotes PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in .../src/Jaeger/Codec/TextCodec.php on line 162, reported from PHP 8.1 with the maintainer asking for a pull request. Line 162 is $parts = explode(':', $value); inside spanContextFromString($value), which splits a trace header into four parts and throws Exception('Malformed tracer state string.') when the count is wrong. The caller is extract($carrier) at line 84: it loops over the carrier's headers, and for the trace id header passes the value straight through, after urldecode($value) at line 98 when the codec was built with urlEncoding on.

Then it reproduces with the project's own tooling. composer install brings PHPUnit (^7 || ^8 || ^9) and PHP_CodeSniffer with the PSR2 ruleset in phpcs.xml.dist; composer test passes on PHP 8.2. The suite never sends a null header, which is why it is green: testInvalidSpanContextParsingFromHeader sends 'invalid_data' and expects the malformed-state exception, and testExtractEmptySpanContext sends an empty carrier. A four-line script that calls extract(['uber-trace-id' => null]), the shape a request wrapper produces when it looks up a header that is not there, prints the deprecation at line 162 and then the exception; with URL decoding on, urldecode(): Passing null to parameter #1 ($string) fires first at line 98.

The fix follows the code's own convention. A null trace header is a malformed one, so the agent adds an is_string check at the top of spanContextFromString that throws the same Malformed tracer state string. exception, and guards the urldecode call the same way. Tracer::extract at line 267 already wraps the codec call in a try, logs the message as a warning and returns null, so the caller sees exactly what it sees for 'invalid_data' today: no context, one log line, no deprecation. The agent adds a test case beside the existing invalid-data one with a null value, reruns PHPUnit with the new case and phpcs, which reports nothing.

It also reads the CI matrix in .github/workflows/main.yaml, which runs PHP 7.1 through 8.1, and notes that the deprecation only shows from 8.1 up and that the check runs on 8.2 or later, so the maintainer can decide whether to extend the matrix in the same change or a later one.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Our PHP library logs \"Passing null to parameter #2 ($string) of type string is deprecated\" from explode() on PHP 8.1. Find the line, trace how a null reaches it from the public method, and fix it the way the code already handles invalid input, without changing the exception or return value callers see. Check the same path for any other built-in that would also receive the null. Add a test that sends the null, run the test suite and the code sniffer before and after on PHP 8.1 or later, and open a pull request that quotes the deprecation and references the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that touches src/Jaeger/Codec/TextCodec.php in two places, the guard before explode and the guard before urldecode, and adds one test to tests/Jaeger/Codec/TextCodecTest.php. The description quotes both deprecation lines with their line numbers, shows the PHPUnit count before and after and a clean phpcs run, names the PHP version used, and links issue #133.

A reviewer checks that the behaviour for a null header is the existing malformed-state exception rather than a new code path, that Tracer::extract still turns it into a warning and a null return, and whether the CI matrix should gain PHP 8.2 and later so the deprecation would have been caught.

Run it on every deprecation line in production logs

The signal is the log line itself. A handler on your server that watches the application log for Passing null to parameter sends this request with the quoted line in input, with its own UUID as request_id so the same line seen twice starts one run, and reads the run.completed webhook to post the pull request link back where the alert came from.

For a PHP upgrade across many services, your server sends this request once per repository, each with its own UUID as request_id so a retry returns the run already started; a key starts at most max_concurrent runs at once and queues the rest.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

A deprecation like this is harmless today and a TypeError in a future PHP, and the tempting fix, casting to a string, hides the fact that a required header was missing. In a Rush sandbox the agent runs the library's own PHPUnit and PHP_CodeSniffer on a PHP that prints the deprecation, writes the test the suite was missing, and shows the green run with the warning gone.

The path from a public method to a built-in call is the part people get wrong under time pressure. The agent traces it from extract through the decoding branch to explode, finds the second site, and explains why the fix reuses the exception the caller already handles.

Frequently asked questions

Why not cast the value with (string) and move on?

Because a null trace header is not an empty trace header. Casting turns it into an empty string that still fails the four-part check, so the exception is the same, but the code would stop saying what happened. The guard throws the existing malformed-state exception at the point where the input is known to be wrong.

Will callers see a different exception or return value?

No. Tracer::extract catches anything the codec throws, logs the message as a warning and returns null, which is what it does for a malformed string today. The pull request's new test asserts the same exception message for a null value.

Is explode the only built-in affected?

On this path there are two: explode at line 162 and, when the codec URL-decodes headers, urldecode at line 98, which fires first. The agent guards both and shows each deprecation line in the pull request so the second one does not come back as a new issue.

Which PHP versions print this?

PHP 8.1 and later. The repository's CI matrix stops at 8.1, so a test on 8.2 or newer is where the agent reproduces it; the pull request says which version it used and leaves extending the matrix to you.

More PHP jobs

More jobs like this: Fix a bug from an alert

Keep reading