From 127ef175b7632ba846c4a8081a575e3df69ba947 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 30 Sep 2022 12:00:02 -0400 Subject: [PATCH] Add support for `$items[] = $item;` append syntax to WireArray/PageArray --- wire/core/WireArray.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wire/core/WireArray.php b/wire/core/WireArray.php index 783205ef..b64ede4c 100644 --- a/wire/core/WireArray.php +++ b/wire/core/WireArray.php @@ -11,7 +11,7 @@ * * @todo can we implement next() and prev() like on Page, as alias to getNext() and getPrev()? * - * ProcessWire 3.x, Copyright 2021 by Ryan Cramer + * ProcessWire 3.x, Copyright 2022 by Ryan Cramer * https://processwire.com * * @method WireArray and($item) @@ -557,6 +557,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count if(is_array($key)) { if(ctype_digit(implode('', array_keys($key)))) { $items = array(); + /** @var array $key */ foreach($key as $k) { $item = $this->get($k); $items[$k] = $item; @@ -1839,7 +1840,12 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count */ #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { - $this->set($offset, $value); + if($offset === null) { + // i.e. $wireArray[] = $item; + $this->add($value); + } else { + $this->set($offset, $value); + } } /**