Skip to content

Conversation

@mawiswiss
Copy link
Contributor

This fixes the following error appearing on the GraphQL endpoint: Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

What 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:

@mawiswiss mawiswiss force-pushed the preg_replace-deprecation branch from 77b361d to ca56a06 Compare March 10, 2025 17:56
@mawiswiss mawiswiss closed this Mar 10, 2025
@mawiswiss mawiswiss reopened this Mar 10, 2025
Copy link
Collaborator

@justlevine justlevine left a 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.

@justlevine justlevine changed the title Avoid the deprecation warning on GraphQL endpoint fix: Avoid the deprecation warning on GraphQL endpoint Mar 10, 2025
@justlevine justlevine changed the title fix: Avoid the deprecation warning on GraphQL endpoint fix: Avoid the deprecation warning when sending null header values Mar 10, 2025
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`
@mawiswiss mawiswiss force-pushed the preg_replace-deprecation branch from ca56a06 to 8151e94 Compare March 10, 2025 18:30
@justlevine justlevine added status: in review Awaiting review before merging or closing needs: reviewer response This needs the attention of a codeowner or maintainer needs: author response Additional Pending information from the author has been requested from the author and removed needs: reviewer response This needs the attention of a codeowner or maintainer labels Mar 10, 2025
@coveralls
Copy link

coveralls commented Mar 10, 2025

Coverage Status

coverage: 82.648%. remained the same
when pulling b932ecf on marcwieland95:preg_replace-deprecation
into 8f56e14 on wp-graphql:develop.

@jasonbahl
Copy link
Collaborator

@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 null values are being passed.

I'll update the docblock to reflect as much and this solution will convert null values to an empty string to play nice.

@jasonbahl
Copy link
Collaborator

@justlevine I updated the docblock to reflect the reality of how the function is already being used. b932ecf

@jasonbahl jasonbahl added the ready-for-changeset Label used by maintainers to indicate a Pull Request is ready to have a changeset applied. label Mar 10, 2025
github-actions bot pushed a commit that referenced this pull request Mar 10, 2025
@github-actions github-actions bot removed the ready-for-changeset Label used by maintainers to indicate a Pull Request is ready to have a changeset applied. label Mar 10, 2025
@justlevine
Copy link
Collaborator

justlevine commented Mar 10, 2025

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 null values are being passed.

@jasonbahl there's a difference between assuming and encouraging though.

8151e94 was already enough to defensively prevent people from passing null IRL.

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 (?string) or to only send a header if it has a value (string).

I strongly lean towards the latter.

@jasonbahl
Copy link
Collaborator

@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.

@justlevine
Copy link
Collaborator

@justlevine do you think it would make sense to add a deprecation notice within the send_header method to discourage null inputs?

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.

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.

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 null doesn't cause an issue despite the function wanting a string 🤷

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 43dda0d and detected 0 issues on this pull request.

View more on Code Climate.

@jasonbahl jasonbahl merged commit 610209f into wp-graphql:develop Mar 10, 2025
4 checks passed
@iandrewt
Copy link

Looks like this PR got reverted in this commit: 835321e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: author response Additional Pending information from the author has been requested from the author status: in review Awaiting review before merging or closing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants