fix: use explicit nullable type for visit() $model (PHP 8.4)#75
Merged
Conversation
PHP 8.4 deprecates implicitly nullable parameters when the type is non-nullable but the default is null (RFC / migration notes). visit(Model $model = null) triggers: Implicitly marking parameter $model as nullable is deprecated, the explicit nullable type must be used instead. This changes the signature to visit(?Model $model = null), which is equivalent at runtime and removes the deprecation.
fix: use explicit nullable type for visit() $model (PHP 8.4)
Member
|
Could you please write a proper description for your PR? |
Contributor
Author
updated |
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.
Pull request: shetabit/visitor — PHP 8.4 explicit nullable
visit()parameterUse this body when opening a PR against shetabit/visitor (
master).Description
Update
Shetabit\Visitor\Visitor::visit()so the$modelparameter uses an explicit nullable type:?Model $model = nullinstead ofModel $model = null.Optionally align the docblock with the signature, e.g. change
@param Model $modelto@param Model|null $model(behavior is unchanged; only the declared type matches PHP 8.4).Motivation and context
PHP 8.4 deprecates implicitly nullable parameters: a non-nullable type with a default of
nullmust be written as nullable (?TypeorType|null). Without this, loading the class triggers:Implicitly marking parameter $model as nullable is deprecated, the explicit nullable type must be used insteadThis change removes that deprecation and matches the same nullable style already used elsewhere in the class (e.g.
setVisitor(?Model $user)). It is not a behavior change: callers could already passnullvia the default; the runtime contract is the same.If it fixes an open issue, link it here (e.g.
Fixes #numorcloses #num).How has this been tested?
shetabit/visitoris loaded.php -l src/Visitor.phppasses after the edit.composer check-styleandcomposer test(orvendor/bin/phpunit) aftercomposer install.app('shetabit-visitor')) and confirm the deprecation notice forVisitor::visit()no longer appears in logs.No other code paths were changed; call sites that pass a
Model, omit the argument, or rely on the default remain valid.Screenshots (if appropriate)
N/A (no UI changes).
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:Checklist
Go over all the following points, and put an
xin all the boxes that apply.Notes:
visit(null)or resolvingshetabit-visitor) so the tests checkbox is accurate.visit(); the README likely stays unchanged.Code change (reference)
Optional docblock tweak:
@param Model|null $model.