diff --git a/lib/zin/core/command.class.php b/lib/zin/core/command.class.php index 9d8577b4f7..41bf33d851 100644 --- a/lib/zin/core/command.class.php +++ b/lib/zin/core/command.class.php @@ -173,8 +173,9 @@ class command return $list; } - public static function first(array $nodes, string|array|object $selectors) + public static function first(array $nodes, string|array|object|null $selectors = null) { + if($selectors === null) return reset($nodes); foreach($nodes as $node) { $result = $node->findFirst($selectors); @@ -183,8 +184,9 @@ class command return array(); } - public static function last(array $nodes, string|array|object $selectors) + public static function last(array $nodes, string|array|object|null $selectors = null) { + if($selectors === null) return end($nodes); foreach($nodes as $node) { $result = $node->findLast($selectors); diff --git a/lib/zin/core/node.class.php b/lib/zin/core/node.class.php index 29915cb06e..d7ed3105cd 100644 --- a/lib/zin/core/node.class.php +++ b/lib/zin/core/node.class.php @@ -176,13 +176,13 @@ class node implements \JsonSerializable public function findFirst(string|array|object $selectors): ?node { $results = $this->find($selectors, true); - return empty($results) ? null : $results[0]; + return empty($results) ? null : reset($results); } public function findLast(string|array|object $selectors): ?node { $results = $this->find($selectors, true, true); - return empty($results) ? null : $results[0]; + return empty($results) ? null : reset($results); } public function prop(array|string $name, mixed $defaultValue = null): mixed