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)
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
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
- 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).
- 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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AdvancedCustomFields/acf
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1041 · 1 bình luận ·
-
True / False ACF control bug on RTL layoutsCó thể đã có người làm @elicohenator đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1038 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1034 · 2 bình luận ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+Có thể đã có người làm @antwonw đã nhận 31 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1032 · 1 bình luận ·
-
Drop trap, acf_after_titleCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1029 · 1 bình luận ·
Tất cả issue của AdvancedCustomFields/acf
Issue tương tự
-
bug code quality
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SemanticMediaWiki/SemanticMediaWiki#7149 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
google/site-kit-wp#13825 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Made by AI module: MCP type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100