rfc:collections
This is an old revision of the document!
PHP RFC: Collections
- Version: 0.1.0
- Date: 2023-04-24
- Author: Derick Rethans derick@php.net
- Status: Draft
- First Published at: http://wiki.php.net/rfc/collections
Introduction
This RFC suggests to introduce a new
Definitions
Term | Description |
---|---|
Biscuits | Better than cookies |
Proposal
Basics
Design Goals:
- keep it simple
- default behaviour should be the most expected
- prefer a method per function, instead of allowing the behaviour of a method to be changed through (optional) arguments.
- operations are on graphemes
- no redundant methods that can be constructed from other methods, unless they already exist in PHP, or are frequently used
- more as we discuss this...
Non Design Goals:
- introduce every feature of the intl extension
Syntax
collection Articles(int => Article) { }
Is short hand for, but acts like ArrayAccess too:
class Articles {
private array $__collection_items;
public function __construct() { $this->__collection_items = []; }
public function offsetExists(int $offset): bool { return array_key_exists($offset, $this->__collection_items); }
public function offsetGet(int $offset) : ?Article { return $this->offsetExists($offset) ? $this->__collection_items[$offset] : NULL; }
public function offsetSet(int $offset, Article $item) : void { $this->__collection_items[$offset] = $item; }
public function offsetUnset(int $offset): void { unset($this->__collection_items[$offset]); }
}
Implementation Details
Backward Incompatible Changes
Proposed PHP Version(s)
Next PHP 8.x
RFC Impact
There will be no impact to SAPIs, existing extensions, nor Opcache.
Open Issues
Questions and Answers
Why is this not a composer package?
Future Scope
Proposed Voting Choices
Either “yes” or “no” on including the proposed class.
Patches and Tests
There is no patch yet.
Implementation
After the project is implemented, this section should contain
- the version(s) it was merged into
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
- a link to the language specification section (if any)
References
Rejected Features
Nothing rejected yet.
Changes
0.1.0 — 2023-04-24
- Initial Draft
rfc/collections.1683042005.txt.gz · Last modified: 2023/05/02 15:40 by derick