Skip to content
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

Prevent fatal error on erroneous options on PHP 8.0+ #18282

Closed
wants to merge 0 commits into from

Conversation

Djennez
Copy link
Member

@Djennez Djennez commented Mar 29, 2022

Context

  • PHP 8.1 throws a fatal if a non-countable object is thrown at count(). Therefore the default option value of [] will error and we would want to return before that.
  • So far, this error is only observed when updating from a version prior to 17.7 to a version after 17.9 because of possible object caching. But I think it's annoying enough to build a bit more reinforcement to prevent it from happening.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a possible fatal error on PHP 8.1 when the options framework is returning invalid options.

Relevant technical choices:

  • Looked at setting the default value of $this->options_helper->get( 'workouts_data', [] ); to return something like [][][], but that does not work and isn't clear. So eventually opted to just return false if the default empty array is detected.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Install default WordPress / plugin on PHP 8.1
  • In wordpress-seo/src/integrations/admin/workouts-integration.php change line 480 $workouts_option = $this->options_helper->get( 'workouts_data', [] ); to $workouts_option = []; to emulate the return of a default empty array.
  • When visiting your sites' dashboard, notice fatal errors being thrown when not using this PR.
  • With this PR, no fatal error is thrown.

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change.

Quality assurance

  • I have tested this code to the best of my abilities
  • I have added unittests to verify the code works as intended
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.

Fixes #17961

@Djennez Djennez added community-patch changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog labels Mar 29, 2022
@Djennez Djennez changed the title Prevent fatal error on erroneous options on PHP 8.1 Prevent fatal error on erroneous options on PHP 8.0+ Mar 29, 2022
@enricobattocchi
Copy link
Member

That part of the code has been removed, so I'm closing the issue.

@enricobattocchi enricobattocchi deleted the prevent_non_countable_to_count branch September 22, 2022 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog community-patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in workouts-integration.php affected admin on php 8 or later
2 participants