EE-293: Declare the optional parameters as explicit nullable types - #19
Merged
mSprunskas merged 11 commits intoSep 30, 2026
Merged
mSprunskas merged 11 commits into
mSprunskas merged 11 commits into
Conversation
PHP 8.4 deprecates a typed parameter that is nullable only because its default is null. Loading the library printed eight such notices: the $default of getBool(), getFloat(), getInt() and getString(), and $message and $previous in the three exception constructors. The parameters now say ?type. The accepted values are the same, so no caller or subclass changes, and PHP 7.1 still parses it. A new test loads every class in a separate process and fails if PHP reports a deprecation for the library. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The suite never called getKey(), setMessage(), getExpectedType() or getGivenType(), and never converted a list of lists to an array. Line coverage was 90 of 96. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
PHPUnit runs data providers before it starts measuring coverage, so setMessage(), called while the provider built its case, was counted as never run although the test asserts its result. Each case now passes a function that builds the exception during the test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The test listed four classes by hand, so a class added later would escape it, and it ignored whether a class loaded at all. It now walks src/ and reports any file whose class does not load. The child process also starts with -n. It used to read the machine's php.ini: a startup notice from an old setting failed the test on a clean library, and with opcache enabled for the command line the deprecations bypassed the error handler, so the test passed on the code it exists to catch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Only InvalidItemException's two parameters were passed an explicit null in a test. The four getters' $default and the $previous of the other two exceptions now are as well, which is the one thing the nullable types must keep accepting. The new test methods declare their void return type. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Keep the loading test and the explicit-null cases for the eight parameters. Remove the cases for code the release does not change (the exceptions' setMessage() and non-null previous exceptions, getDataAsArray() over nested lists), which were added only to raise line coverage. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mSprunskas
reviewed
Sep 30, 2026
The three exception classes now import Exception, the way ObjectWrapper imports RuntimeException. Nothing a caller sees changes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every case passed null for the previous exception, and none passed a message to InvalidItemException. Each exception now gets a case with a previous exception, compared as the same object, and InvalidItemException gets one with a custom message. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
convertDeprecationsToExceptions makes PHPUnit 9 fail a test that triggers a deprecation, and the tests load every class under src/, so the PHP 8.4 jobs now fail on an implicitly nullable parameter without a test of their own. PHPUnit 6 converts deprecations already. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mSprunskas
approved these changes
Sep 30, 2026
6 tasks done
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
On PHP 8.4, loading this library prints eight "Implicitly marking parameter … as nullable is deprecated" notices. This declares the eight parameters as explicit nullable types, which removes them. Nothing a caller passes or receives changes. I propose releasing it as 0.4.2.
Why
null.$defaultofgetBool(),getFloat(),getInt()andgetString(), and$message/$previousof the constructors ofInvalidItemException,InvalidItemTypeExceptionandMissingItemException.getIterator(): ArrayIterator, which would break subclasses. This change does only the parameters and keeps PHP 7.1.Changes
src/:bool $default = nullbecomes?bool $default = null, and the same for the other seven. The exception classes also importExceptioninstead of naming it\Exception. Nothing else insrc/changes.phpunit.xml.dist:convertDeprecationsToExceptions="true". PHPUnit 9 then fails a test that triggers a deprecation, and the tests load every class undersrc/, so the PHP 8.4 jobs fail if an implicitly nullable parameter comes back. PHPUnit 6, used on PHP 7.1 and 7.2, converts deprecations already.nullon all eight parameters, for a previous exception on each exception class, and for a custom message. The suite goes from 47 to 58 tests, and line coverage from 90 of 96 lines to 93 of 96.CHANGELOG.md: 0.4.2.Backward compatibility
?bool $default = nullandbool $default = nulldeclare the same type. They accept the same values, and PHP treats them as identical for subclasses. A backward-compatibility check from 0.4.1 finds no change in the library's API.?typeneeds PHP 7.1, whichcomposer.jsonalready requires. So this is a patch release.Not in this change: on PHP 8.5,
getIterator()passes the wrapped object itself toArrayIterator, which 8.5 deprecates. The obvious fix changes numeric iteration keys from strings to integers, so it needs its own change.Test plan
🤖 Generated with Claude Code