: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Blocks API: WP_Block_List class
* Class representing a list of block instances.
#[AllowDynamicProperties]
class WP_Block_List implements Iterator, ArrayAccess, Countable {
* Original array of parsed block data, or block instances.
* @var array[]|WP_Block[]
* All available context of the current hierarchy.
protected $available_context;
* Block type registry to use in constructing block instances.
* @var WP_Block_Type_Registry
* Populates object properties from the provided block instance argument.
* @param array[]|WP_Block[] $blocks Array of parsed block data, or block instances.
* @param array $available_context Optional array of ancestry context values.
* @param WP_Block_Type_Registry $registry Optional block type registry.
public function __construct( $blocks, $available_context = array(), $registry = null ) {
if ( ! $registry instanceof WP_Block_Type_Registry ) {
$registry = WP_Block_Type_Registry::get_instance();
$this->available_context = $available_context;
$this->registry = $registry;
* Returns true if a block exists by the specified block offset, or false
* @link https://www.php.net/manual/en/arrayaccess.offsetexists.php
* @param string $offset Offset of block to check for.
* @return bool Whether block exists.
public function offsetExists( $offset ) {
return isset( $this->blocks[ $offset ] );
* Returns the value by the specified block offset.
* @link https://www.php.net/manual/en/arrayaccess.offsetget.php
* @param string $offset Offset of block value to retrieve.
* @return mixed|null Block value if exists, or null.
public function offsetGet( $offset ) {
$block = $this->blocks[ $offset ];
if ( isset( $block ) && is_array( $block ) ) {
$block = new WP_Block( $block, $this->available_context, $this->registry );
$this->blocks[ $offset ] = $block;
* Assign a block value by the specified block offset.
* @link https://www.php.net/manual/en/arrayaccess.offsetset.php
* @param string $offset Offset of block value to set.
* @param mixed $value Block value.
public function offsetSet( $offset, $value ) {
if ( is_null( $offset ) ) {
$this->blocks[] = $value;
$this->blocks[ $offset ] = $value;
* @link https://www.php.net/manual/en/arrayaccess.offsetunset.php
* @param string $offset Offset of block value to unset.
public function offsetUnset( $offset ) {
unset( $this->blocks[ $offset ] );
* Rewinds back to the first element of the Iterator.
* @link https://www.php.net/manual/en/iterator.rewind.php
public function rewind() {
* Returns the current element of the block list.
* @link https://www.php.net/manual/en/iterator.current.php
* @return mixed Current element.
public function current() {
return $this->offsetGet( $this->key() );
* Returns the key of the current element of the block list.
* @link https://www.php.net/manual/en/iterator.key.php
* @return mixed Key of the current element.
return key( $this->blocks );
* Moves the current position of the block list to the next element.
* @link https://www.php.net/manual/en/iterator.next.php
* Checks if current position is valid.
* @link https://www.php.net/manual/en/iterator.valid.php
public function valid() {
return null !== key( $this->blocks );
* Returns the count of blocks in the list.
* @link https://www.php.net/manual/en/countable.count.php
* @return int Block count.
public function count() {
return count( $this->blocks );