Advantage of ArrayObject vs normal array

See this:
Then what is advantage of ArrayObject vs normal array?

you don’t have to remember whether to put the array as first parameter in the array function or not.

admittedly, the ArrayObject could need some love.

another reason just a couple of lines later:

Long story short b/c arrays by default are passed by value, if you pass an array to a function, the function works on a copy of the array while the original array remains unaltered by the function.

Very little unless you extend it. Frustratingly, and they still haven’t fixed this for PHP7, ArrayObjects are not interchangeable with arrays, so methods that require arrays don’t work with ArrayObject instances. Until PHP is capable of transparent conversion between ArrayObject instances and arrays, its usefulness is limited.

@Dormilich You lib seems very nice thanks for sharing the link, I wish you provided more examples! :frowning:

have a look at the unit tests.

1 Like

Hmm…I found this all the way at the bottom of the backlogged TODO list. But no RFC for it.

Make it possible to use objects implementing ArrayObject interface anywhere arrays are used.

At least they know it is a wish for improvement. :wink:


1 Like

Thanks, unit tests are very useful to understand you lib better.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.