Hi all,

I have two questions about the intended behaviour of
ArrayObject::exchangeArray() :

1. What should happen when the argument is an object?

The docs suggest that the arg should be an array, but the prototype in
the code indicates objects are OK too. However, when an object is
passed, the effect is simply to remove the ArrayObject's storage
container, which doesn't seem right: http://pastebin.ca/1091256


2. Should the ArrayObject store a copy or a real reference to the
array passed to exchangeArray()?

Currently, the ArrayObject container effectively becomes a
copy-on-write reference to the array passed to exchangeArray()... but
there is no logic to split the container when it is modified.
Consequently, the behaviour is very ambiguous:
http://pastebin.ca/1091266 .
Depending on the intended behaviour, it seems either exchangeArray()
needs to take its arg as prefer-by-reference, or the arg needs to be
split before being stashed in the ArrayObject.


One way to address both of these issues is to make exchangeArray()
share the logic that sets the array in __construct(). This way,
echangeArray() works with object arguments (with some special cases if
the argument is itself an ArrayObject), and array arguments are split
before being stored in the ArrayObject.

Here's a suggested patch against 5_3 that implements this (and
includes some tests): http://pastebin.ca/1091668
Note that I'm not an internals or SPL expert, so let me know if I
missed something.

Regards,
Robin

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to