From a2e06c78e7b302178e1f720ed358166a7f519e2f Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 11 Sep 2026 12:14:10 +0530 Subject: [PATCH 1/3] Replace array_key_last with array_last --- src/wp-includes/class-wp-block-parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block-parser.php b/src/wp-includes/class-wp-block-parser.php index 81cb7a8fa21f7..6c1eb715a7ac1 100644 --- a/src/wp-includes/class-wp-block-parser.php +++ b/src/wp-includes/class-wp-block-parser.php @@ -342,7 +342,7 @@ public function add_freeform( $length = null ) { * @param int|null $last_offset Last byte offset into document if continuing form earlier output. */ public function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { - $parent = $this->stack[ array_key_last( $this->stack ) ]; + $parent = array_last( $this->stack ); $parent->block->innerBlocks[] = (array) $block; $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ); From 5e5fe909b9897502a92d6036ceb6a6b37337bf0d Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 15 Sep 2026 20:30:31 +0530 Subject: [PATCH 2/3] Revert and add document comment Updated the method to access the last element of the stack using array_key_last() instead of array_last() for better static analysis compatibility. --- src/wp-includes/class-wp-block-parser.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block-parser.php b/src/wp-includes/class-wp-block-parser.php index 6c1eb715a7ac1..8556d8687ac57 100644 --- a/src/wp-includes/class-wp-block-parser.php +++ b/src/wp-includes/class-wp-block-parser.php @@ -342,7 +342,14 @@ public function add_freeform( $length = null ) { * @param int|null $last_offset Last byte offset into document if continuing form earlier output. */ public function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { - $parent = array_last( $this->stack ); + /* + * Note: `array_last()` is intentionally not used here. It returns `null` for an + * empty array, which makes static analysis flag the property accesses below. + * Guarding against that is not possible without changing behavior: both callers + * already ensure the stack is not empty, so the guard would be unreachable, and + * this is a public method on a class that can be replaced via `block_parser_class`. + */ + $parent = $this->stack[ array_key_last( $this->stack ) ]; $parent->block->innerBlocks[] = (array) $block; $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ); From 552c141a5e5629295e4037dc868991c7fd6ba431 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 25 Sep 2026 11:18:53 +0530 Subject: [PATCH 3/3] Restore count()-based stack access and narrow type to a list --- src/wp-includes/class-wp-block-parser.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-block-parser.php b/src/wp-includes/class-wp-block-parser.php index 81f9a42c881b8..3090c238eb4e8 100644 --- a/src/wp-includes/class-wp-block-parser.php +++ b/src/wp-includes/class-wp-block-parser.php @@ -45,6 +45,7 @@ class WP_Block_Parser { * * @since 5.0.0 * @var WP_Block_Parser_Frame[] + * @phpstan-var list */ public $stack; @@ -346,14 +347,7 @@ public function add_freeform( $length = null ) { * @param int|null $last_offset Last byte offset into document if continuing form earlier output. */ public function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { - /* - * Note: `array_last()` is intentionally not used here. It returns `null` for an - * empty array, which makes static analysis flag the property accesses below. - * Guarding against that is not possible without changing behavior: both callers - * already ensure the stack is not empty, so the guard would be unreachable, and - * this is a public method on a class that can be replaced via `block_parser_class`. - */ - $parent = $this->stack[ array_key_last( $this->stack ) ]; + $parent = $this->stack[ count( $this->stack ) - 1 ]; $parent->block->innerBlocks[] = (array) $block; $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );