-
Notifications
You must be signed in to change notification settings - Fork 466
fix: Avoid the deprecation warning when sending null header values #3338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Avoid the deprecation warning when sending null header values #3338
Conversation
77b361d to
ca56a06
Compare
justlevine
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcwieland95 thanks so much for this PR 🙌
Any chance you can provide a trace for the error you're trying to address?
While not enforced by the method signature (luckily for you, since it would fatal), $value is typed to accept a string not a string | null.
I left some feedback to harden this check in a way that isn't negated by passing the correct parameter type, but we should also address the problem at the source before we start obfuscating the real issue.
This fixes the following error appearing on the GraphQL endpoint: `Deprecated: preg_replace(): Passing null to parameter wp-graphql#3 ($subject) of type array|string is deprecated`
ca56a06 to
8151e94
Compare
|
@justlevine the send_header method is typed in the docblock for phpstan, but is not typed in the function signature, and given that it's a public function that can be used by plugins to send headers along with the response, we need to move forward assuming that I'll update the docblock to reflect as much and this solution will convert null values to an empty string to play nice. |
|
@justlevine I updated the docblock to reflect the reality of how the function is already being used. b932ecf |
@jasonbahl there's a difference between assuming and encouraging though. 8151e94 was already enough to defensively prevent people from passing Changing the doc-block, however encourages people to pass null. Question is what's the better path we want to encourage: to pass a header with an empty value ( I strongly lean towards the latter. |
|
@justlevine do you think it would make sense to add a deprecation notice within the send_header method to discourage null inputs? i.e. something like: if ( null === $value ) {
_deprecated_argument( __METHOD__, '@since next-version', 'Passing null values to send_header is deprecated. Please pass a string value.' );
}This way the docblock can accurately represent how the function currently works (regardless of ideals) and actively discourage users from using it in a way we don't encourage? Or we can leave the docblock string as-is (even though null is technically valid) and let the defensive fix do it's thing in the mean time. |
Yes, I'd want to mark this as deprecated for signature change in a future release, but i'd rather wait until we know when that release might happen, and not prematurely force it for 3.0. There's no reason to cause a break over this, so we can slate it strategically to occur alongside related changes.
In lieu of a method signature, the docs define what is "technically valid" (regardless if PHP throws an error), so yeah even if there wasn't a good reason to temporarily hold off on event logging, I personally wouldn't feel too bad about the fact that passing |
…the function" This reverts commit b932ecf.
|
Code Climate has analyzed commit 43dda0d and detected 0 issues on this pull request. View more on Code Climate. |
|
Looks like this PR got reverted in this commit: 835321e |
This fixes the following error appearing on the GraphQL endpoint:
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecatedWhat does this implement/fix? Explain your changes.
…
Breaking Changes
Upgrade Instructions
Does this close any currently open issues?
Any relevant logs, error output, GraphiQL screenshots, etc?
Any other comments?
…
Where has this been tested?
Operating System: …
WordPress Version: …