Extend ArrayObject class
| From: | Aimeos | Norbert Sendetzky | Date: | Sun, 24 Nov 2019 12:16:40 +0000 |
| Subject: | Extend ArrayObject class | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-107851@lists.php.net to get a copy of this message | ||
The ArrayObject class is only rarely used at the moment due to a lack
for almost all array_* functions beside the sort functions.
Currently implemented by ArrayObject:
https://www.php.net/manual/en/class.arrayobject.php
Missing methods that would be most useful:
array_chunk
array_column
array_diff_assoc
array_diff_key
array_diff_uassoc
array_diff_ukey
array_diff
array_filter
array_flip
array_intersect_assoc
array_intersect_key
array_intersect_uassoc
array_intersect_ukey
array_intersect
array_key_first
array_key_last
array_keys
array_map
array_merge
array_pop
array_push
array_rand
array_reduce
array_replace_recursive
array_replace
array_reverse
array_search
array_shift
array_slice
array_splice
array_unique
array_unshift
array_values
shuffle
Furthermore, the already existing sort functions return VOID, which
isn't best for an object. Instead, returning the ArrayObject itself to
support a fluid interface would be much better, i.e.:
$ao = new \ArrayObject([null, 'a' => 2, 'b' => 1]);
$ao->filter()->sort()->flip();
This change wouldn't break any existing code already using the ArrayObject.
It should be possible to extend from ArrayObject too and have access to
the internal array. Therefore, a new method would be required:
protected getArrayRef() : array
The method is similar to the existing getArrayCopy() method but returns
a reference to the internal array instead of a copy. Thus, classes
extending ArrayObject will be able to implement additional methods
efficiently without the need to create copies of the internal array first.