Commit b3a58f5d72 for wordpress.org
commit b3a58f5d721282c958c9155ffb5b6d04976d1a20
Author: westonruter <westonruter@git.wordpress.org>
Date: Tue Sep 15 17:03:48 2026 +0000
Docs: Explain why `array_last()` is not used in the block parser.
Add an inline comment to `WP_Block_Parser::add_inner_block()` recording why the last stack entry is read as `$this->stack[ array_key_last( $this->stack ) ]` rather than with `array_last()`. The latter was tried while preparing r62956 and reverted before it landed, and has since been proposed again.
Because `array_last()` returns `null` for an empty array, using it here reintroduces a static analysis error on the property accesses that follow. Guarding the return value is not an option: both call sites already return early when the stack is empty, so the guard would be unreachable from core, and `add_inner_block()` is a public method on a class that can be replaced via the `block_parser_class` filter, so throwing a new exception type would change behavior for third-party callers. A `@throws` tag for an exception that can never be thrown would in turn flag every caller for not wrapping the call in `try`/`catch`.
Developed in https://github.com/WordPress/wordpress-develop/pull/13487.
Follow-up to r62956.
Props mukesh27, soean, westonruter.
See #65818.
Built from https://develop.svn.wordpress.org/trunk@63624
git-svn-id: http://core.svn.wordpress.org/trunk@62800 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-block-parser.php b/wp-includes/class-wp-block-parser.php
index 3b50c8e30c..81f9a42c88 100644
--- a/wp-includes/class-wp-block-parser.php
+++ b/wp-includes/class-wp-block-parser.php
@@ -346,6 +346,13 @@ class WP_Block_Parser {
* @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->block->innerBlocks[] = (array) $block;
$html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 4994843d1e..980aacef74 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63623';
+$wp_version = '7.2-alpha-63624';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.