PHP 8.5: "Using null as an array offset" deprecation in ACF_Data::is() when rendering a block with empty data (local-meta.php is_request)
评估
调研方向
从 includes/local-meta.php 和 ACF_Local_Meta::is_request() 开始,然后沿着报告的调用路径追踪到 includes/class-acf-data.php:159 及相关的本地字段函数。使用 PHP 8.5 和数据为空的 ACF 区块复现问题;验证在前端和编辑器中渲染时不再出现弃用警告。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
On PHP 8.5, rendering an ACF block that has no saved field data (e.g. a block with no fields of its own that only wraps InnerBlocks) triggers:
Deprecated: Using null as an array offset is deprecated, use an empty string instead in wp-content/plugins/advanced-custom-fields-pro/includes/class-acf-data.php on line 159
It fires once per such block, on the front end and in the block editor.
Cause
ACF_Local_Meta::is_request() calls acf_is_field_key( key( $meta ) ). When the block's data is empty, key( [] ) returns null, which goes through the acf/is_field_key filter → _acf_apply_is_local_field_key() → acf_is_local_field_key( null ) → ACF_Data::is( null ) → isset( $this->data[ null ] ).
Call stack:
includes/class-acf-data.php:159 ACF_Data::is()
includes/local-fields.php:588 acf_is_local_field_key()
includes/local-fields.php:679 _acf_apply_is_local_field_key()
includes/acf-field-functions.php:209 acf_is_field_key() (apply_filters 'acf/is_field_key')
includes/local-meta.php:90 ACF_Local_Meta::is_request()
includes/local-meta.php:62 ACF_Local_Meta::add()
includes/local-meta.php:249 acf_setup_meta()
pro/blocks.php:1131 / 1285 acf_rendered_block_v3() / acf_render_block()
To Reproduce
- PHP 8.5, ACF PRO 6.8.10, WordPress 7.1.3,
WP_DEBUGon. - Register an ACF block with no field group (or no saved values) whose template renders
<InnerBlocks />. - Insert it into a post; the saved markup has no
dataattribute, e.g.<!-- wp:my-plugin/feature {"name":"my-plugin/feature","mode":"preview"} -->. - View the post or open it in the editor: the deprecation above is emitted.
Expected behavior
No deprecation. E.g. in is_request(), return false when $meta is empty (or pass key( $meta ) ?? ''); alternatively make ACF_Data::is() / acf_is_local_field_key() null-safe.
Workaround
Swap ACF's filter callback for a null-safe one (behaviour is unchanged, since PHP already treated a null key as ''):
if ( remove_filter( 'acf/is_field_key', '_acf_apply_is_local_field_key', 20 ) ) {
add_filter( 'acf/is_field_key', fn( $bool, $id ) => acf_is_local_field_key( $id ?? '' ), 20, 2 );
}
Version Information
- WordPress 7.1.3
- PHP 8.5.7
- ACF PRO 6.8.10
Related: #1034 (same PHP 8.5 deprecation, different code path in pro/options-page.php).
- 主要语言
- PHP
- 星标
- 947
- 派生
- 198
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
AdvancedCustomFields/acf 的其他 Issue
-
is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)可能已有人在做 @faisalahammad 于 16 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1041 · 1 条评论 ·
-
True / False ACF control bug on RTL layouts可能已有人在做 @elicohenator 于 39 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1038 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1034 · 3 条评论 ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+可能已有人在做 @antwonw 于 50 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1032 · 1 条评论 ·
-
Drop trap, acf_after_title可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1029 · 1 条评论 ·
查看 AdvancedCustomFields/acf 的全部 Issue
相似的 Issue
-
bug review needed
难度 1/5 1 小时以内 新手友好度 86/100
OpenMage/magento-lts#5816 ·
维护者通常 2 天内回复
-
priority:low type:docs
难度 2/5 1-3 小时 新手友好度 84/100
crazy-goat/rabbit-stream#958 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
nextcloud/richdocuments#6250 ·
维护者通常 1 天内回复
-
sync-en
难度 1/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
sync-en
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 1 天内回复