On Sun, Nov 24, 2019, 13:16 Aimeos | Norbert Sendetzky <norb...@aimeos.com> wrote:
> 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. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.ph > <http://www.php.net/unsub.php> Ouff, please don't extend `ArrayObject`: it is very quirky and keeps state in a way that is very much untransparent to userland: please use `ArrayAccess` instead. Even then, the various `array_` functions that mutate/map/filter would need to produce equivalent data structures by knowing the ctor of your array-alike object: better leave them alone, unless the output is a core `array` again