fix: prevent PHP 8.5 null array offset deprecation in memoizers - #23489
Open
ikamal7 wants to merge 1 commit into
Open
fix: prevent PHP 8.5 null array offset deprecation in memoizers#23489ikamal7 wants to merge 1 commit into
ikamal7 wants to merge 1 commit into
Conversation
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
force-pushed
the
23397-fix-null-array-offset-deprecation
branch
from
July 23, 2026 14:09
6cb43df to
0acec9b
Compare
ikamal7
marked this pull request as ready for review
July 23, 2026 14:14
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.
Context
When an indexable has not been persisted yet (e.g. a Fallback page type with
object_type = 'unknown'), itsidproperty isnull. BothMeta_Tags_Context_MemoizerandPresentation_Memoizeruse$indexable->iddirectly 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:
Deprecated: Using null as an array offsetwarnings were emitted when$indexable->idwas null in the meta tags context and presentation memoizers, caused by unindexed/fallback indexables being used as cache keys.Relevant technical choices:
$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.clear()methods of both classes.''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:
WP_DEBUGandWP_DEBUG_LOGenabled.wp-content/debug.log— noDeprecated: Using null as an array offsetwarnings from Yoast's memoizer classes should appear.Relevant test scenarios
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 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:
Other environments
[shopify-seo], added test instructions for Shopify and attached theShopifylabel to this PR.[yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached theGoogle Docs Add-onlabel to this PR.Documentation
Quality assurance
grunt build:imagesand committed the results, if my PR introduces or edits images or SVGs.Innovation
innovationlabel.Fixes #23397