Hello Robin, Sunday, August 3, 2008, 1:07:56 PM, you wrote:
> 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 Seems like an error message is missing there. It allows to take an instance of another ArrayObject/Iterator and use the array from that. In case any other Object is passed it is ignored. What do you feel? > 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. Seems about right. Can you attach the patch as a text file (I cannot open the link). Best regards, Marcus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php