note 126811 added to class.arrayobject

From: Date: Sun, 30 Jan 2022 01:07:37 +0000
Subject: note 126811 added to class.arrayobject
Groups: php.notes 
Request: Send a blank email to php-notes+get-217555@lists.php.net to get a copy of this message
If you need the last key of your collection use: <?php array_key_last($this->getArrayCopy()) ?> In an extending class it could look like: <?php class Collection extends ArrayObject { public function lastKey(): int { return array_key_last($this->getArrayCopy()); } } ?> If you want to use any type safe collection: <?php class BookCollection extends Collection { public function add(Book $book) : void { $this->offsetSet($book->id, $book); } // note the return type "Book" public function get(int $bookId) : Book { $this->offsetGet($bookId); } } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 2a02:908:1066:eac0:5477:5adf:e090:3e46) ---- Manual Page -- https://php.net/manual/en/class.arrayobject.php Edit -- https://main.php.net/note/edit/126811 Del: integrated -- https://main.php.net/note/delete/126811/integrated Del: useless -- https://main.php.net/note/delete/126811/useless Del: bad code -- https://main.php.net/note/delete/126811/bad+code Del: spam -- https://main.php.net/note/delete/126811/spam Del: non-english -- https://main.php.net/note/delete/126811/non-english Del: in docs -- https://main.php.net/note/delete/126811/in+docs Del: other reasons-- https://main.php.net/note/delete/126811 Reject -- https://main.php.net/note/reject/126811 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217555) next »