On 12/5/2009 3:25 AM, Theriault wrote:
> Doesn't this also mean that array_pop, array_push, array_shift,
> array_unshift, and array_splice are broken in IE?
Yes, it would--but fortunately I suppose, only array_pop() and
array_splice() even made an attempt to support associative arrays.
array_pop() is kind of ok (at least with the fix I made just now) since
IE at least iterates in order, though I put a warning there (and in
array_splice()).
I added functionality in array_push() for associative arrays, again with
a disclaimer.
I still need to get array_shift() and array_unshift() to work,
renumbering keys as in PHP (similar to how it is done in array_splice()
though I need to check my work there too), and will need to add a
warning there too.
> How would these
> return a copy of the array when the return values of these functions
> are expected to be the extracted elements or the new length? Or by
> "return," did you mean replace the original with the new copy?
>
I think for these we should just recommend against use of the functions
for associative arrays unless in a non-IE environment. The functions
should still work as expected for genuine arrays.
> I think I'm leaning towards #1 [Doing non-PHP way of returning copy], regardless. IE has a huge market share
> and people could end up spending hours debugging this problem if they
> didn't read the fine print. I see more problems occurring with not
> having it act the way it's expected to act than replacing the original
> with a copy (which is also not acting the way it's expected to act,
> but less severe in my eyes).
>
Yeah... I've also added support for the other way though if one is in a
non-IE environment (like FF extensions), but it requires an ini_set()
call...
best wishes,
Brett
Although ECMAScript allows implementation-dependent behavior for
iteration, most implementations do at least iterate in order, although
IE has the additional caveat (which doesn't concern us too much since we
should filter with hasOwnProperty() and not expect extended objects)
that it iterates in the opposite order for properties on the prototype.
See
http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/0568e4abfc40a935?
for more details...
> I really dislike the wrapping everything. It will make all array
> functions dependent and probably a lot slower as well. I would hate
> for php.js to turn that way.
>
Sure, though it can be done with some optimizations (see also the
thread). If we required people use "array()) to wrap their arrays, it
could be more doable that way.
> Theriault makes a good point. With array_shift it's just not possible
> to return the modified array(object). So with #1 we're going to have
> to add 'fine print' anyway, warning that IE users will have a
> array_shift implementation that looks nothing like PHP's original
> (cause we're returning both [item, modiefied_object] or sth).
>
>
We previously didn't support objects at all, though I've added that
support except for array_shift() and array_unshift() (which I hope to do
soon if I get some time), but warned against their use in IE. I think
that will be less ugly in these cases then returning both (and they
still can use the functions with real arrays). Though I guess we could
add another configuration mode which allows both to be returned. Thoughts?
> I understand from the topic that shredding the original var and
> replacing it with a copy will not work. I'd like to examine that a
> little further cause it would be the lightweight solution.
>
No, that is not possible, unless we require the array name to be passed
in as a string and then reach out on the object, though that requires
that the input array be a global (kind of like we were forced to do with
settype()). So, that wouldn't work very well.
Brett
--
Also, we still need array_multisort() (Theriault?) to be fixed to work
with the configuration of returning the sorted array by default unless
"phpjs.strictForIn" ini is configured otherwise, though there's a bit of
a note there now about it....
Brett