Improve PHP 8.4+ support by avoiding implicitly nullable types#123
Merged
Improve PHP 8.4+ support by avoiding implicitly nullable types#123
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves compatibility with PHP 8.4+ by avoiding “implicitly nullable” parameter type declarations (typed parameters with a null default), replacing them with untyped parameters plus explicit runtime validation while keeping support for older PHP versions.
Changes:
- Removed implicitly-nullable parameter type hints from
ServerandClientconstructors and added manualinstanceofvalidation with clearInvalidArgumentExceptionmessages. - Added PHPUnit coverage for invalid constructor arguments (
loop/connector). - Updated dependency constraints and CI to include PHP 8.4.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Server.php |
Drops implicitly-nullable constructor type hints and adds explicit runtime validation for $loop/$connector. |
src/Client.php |
Drops implicitly-nullable constructor type hint and adds explicit runtime validation for $connector. |
tests/ServerTest.php |
Adds tests asserting constructor rejects invalid $loop/$connector types with expected messages. |
tests/ClientTest.php |
Adds test asserting constructor rejects invalid $connector type with expected message. |
composer.json |
Updates ReactPHP-related dependency version constraints. |
.github/workflows/ci.yml |
Adds PHP 8.4 to the test matrix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This changeset improves PHP 8.4+ support by avoiding implicitly nullable types as discussed in reactphp/promise#260. The same idea applies, but v1 requires manual type checks to support legacy PHP versions as the nullable type syntax requires PHP 7.1+ otherwise.
The
clue/connection-manager-extradev dependency used in some examples is not affected here because the specific classes used do not use implicitly nullable types (see clue/reactphp-connection-manager-extra#41).Builds on top of #122, #121, #113, reactphp/promise#260, reactphp/socket#318 and others