Skip to content

fix: prevent PHP 8.5 null array offset deprecation in memoizers - #23489

Open
ikamal7 wants to merge 1 commit into
Yoast:trunkfrom
ikamal7:23397-fix-null-array-offset-deprecation
Open

fix: prevent PHP 8.5 null array offset deprecation in memoizers#23489
ikamal7 wants to merge 1 commit into
Yoast:trunkfrom
ikamal7:23397-fix-null-array-offset-deprecation

Conversation

@ikamal7

@ikamal7 ikamal7 commented Jul 23, 2026

Copy link
Copy Markdown

Context

When an indexable has not been persisted yet (e.g. a Fallback page type with object_type = 'unknown'), its id property is null. Both Meta_Tags_Context_Memoizer and Presentation_Memoizer use $indexable->id directly as an array key for their internal cache, which triggers a PHP deprecation warning on PHP 8.1+ and a fatal deprecation on PHP 8.5+.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where PHP Deprecated: Using null as an array offset warnings were emitted when $indexable->id was null in the meta tags context and presentation memoizers, caused by unindexed/fallback indexables being used as cache keys.

Relevant technical choices:

  • Replaces direct $this->cache[ $indexable->id ] with $cache_key = $indexable->id ?? '' so a null ID safely maps to an empty-string key instead of triggering the deprecation.
  • Applied the same fix in the clear() methods of both classes.
  • PHP's array-key semantics treat '' identically to what was previously a null-coerced-to-'' on older PHP versions, so this is a no-op for PHP < 8.1.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  1. Set up a WordPress site running PHP 8.5+ with WP_DEBUG and WP_DEBUG_LOG enabled.
  2. Install and activate Yoast SEO from this branch.
  3. Navigate to Posts → Add New.
  4. Check wp-content/debug.log — no Deprecated: Using null as an array offset warnings from Yoast's memoizer classes should appear.
  5. Verify that the post editor loads correctly and the Yoast SEO metabox functions normally.

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

This is an internal PHP fix with no frontend or editor-specific changes. Testing on a single post type is sufficient.

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:

Not applicable — this is a non-user-facing PHP deprecation fix. The acceptance test steps above are sufficient.

Impact check

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

  • The Yoast SEO metabox initialization and page rendering — the memoizers are called early during admin page loads and frontend page rendering.

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.
  • This PR also affects Yoast SEO for Google Docs. I have added a changelog entry starting with [yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached the Google Docs Add-on label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests 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.
  • I have checked that the base branch is correctly set.
  • I have run grunt build:images and committed the results, if my PR introduces or edits images or SVGs.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #23397

Uses $indexable->id ?? '' as the cache key instead of $indexable->id
directly, so that a null id on unindexed/fallback indexables does not
trigger a PHP Deprecated warning.

Fixes Yoast#23397
@ikamal7
ikamal7 force-pushed the 23397-fix-null-array-offset-deprecation branch from 6cb43df to 0acec9b Compare July 23, 2026 14:09
@ikamal7
ikamal7 marked this pull request as ready for review July 23, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP Deprecated: Using null as an array offset is deprecated warnings for PHP 8.5

2 participants