Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues



Hello Martin,

Tuesday, January 30, 2007, 8:45:50 PM, you wrote:

function f()
{
global $arr;

foreach($arr as $k=>$v) {
$v->do_something();
}
}

I don't see your point anywhere... foreach iterates over a copy of
the array so where is the potential side-effect? Even so there will
be references if the items of the original array are references, or
if they are objects in PHP5, but that's expected behaviour. That's
the way many OOP languages have been implemented (eg: Java) without
coders having the problems you mention. Just give me one good
reason to even consider your proposal.


Humm, you seem to have misunderstood (& that could be one reason in itself). In my example foreach() iterates over the original $arr array (contrary to what you say) - and so may deeply nested fns in the called do_something() method, making global + foreach construct unuseable/"unstable" in non-trivial cases.

--
Best regards,
speedy mailto:speedy.spam@xxxxxxxxx
.



Relevant Pages

  • RE: Array of objects
    ... At the end, @arr contains n ... > object, ref of object. ... Array contains different references, but same ...
    (perl.beginners)
  • RE: Array of objects
    ... > I have to store list of objects in Array. ... At the end, @arr contains n ... Array contains different references, but same ...
    (perl.beginners)
  • Re: Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
    ... > the array so where is the potential side-effect? ... > be references if the items of the original array are references, ... In my example foreach() iterates over the original $arr array ...
    (php.general)
  • Re: Evaluating unary *
    ... 'arr' exists, ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... lea eax, ...
    (comp.std.c)
  • Re: Test if memory pointer is valid?
    ... I can see setting a new pointer initially to the address of the beginning of an array, for example, and then incrementing the pointer to address subsequent elements, but that would usually be done inside a function, where the new pointer would go out of scope at the end of the function and be reinitialized if it is called again. ... I would like to see a specific example where it is necessary to have multiple references such as this where it would be necessary to check for it having been freed. ... copies of all the TLabel references already in the form as individual ...
    (comp.lang.pascal.delphi.misc)