Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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)

Đang mở Phù hợp với người mới
#1,044 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với includes/local-meta.php và ACF_Local_Meta::is_request(), sau đó lần theo đường dẫn lời gọi được báo cáo đến includes/class-acf-data.php:159 và các hàm trường cục bộ liên quan. Tái hiện lỗi với PHP 8.5 và một khối ACF có dữ liệu trống; xác minh rằng cảnh báo deprecation không còn xảy ra khi render ở giao diện người dùng và trong trình chỉnh sửa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
PHP
Star
947
Fork
197
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AdvancedCustomFields/acf

Tất cả issue của AdvancedCustomFields/acf

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.