Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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)

未关闭 适合新手
#1,044 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@faisalahammad 已经在做这个了。

开始于 2026年10月12日。

  • #1047 来自 @faisalahammad —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend

调研方向

从 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

  1. PHP 8.5, ACF PRO 6.8.10, WordPress 7.1.3, WP_DEBUG on.
  2. Register an ACF block with no field group (or no saved values) whose template renders <InnerBlocks />.
  3. Insert it into a post; the saved markup has no data attribute, e.g. <!-- wp:my-plugin/feature {"name":"my-plugin/feature","mode":"preview"} -->.
  4. 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AdvancedCustomFields/acf 的其他 Issue

查看 AdvancedCustomFields/acf 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。