Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: speedy.spam@xxxxxxxxx (speedy)
- Date: Tue, 30 Jan 2007 21:46:36 +0100
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
.
- Follow-Ups:
- Re: Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: "Martin Alterisio"
- Re: Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
- References:
- nested, referenced foreach & implicit current array pointer issues
- From: speedy
- Re: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: "Martin Alterisio"
- nested, referenced foreach & implicit current array pointer issues
- Prev by Date: Re: [PHP] time
- Next by Date: Re: Passing a url-specified value through a form
- Previous by thread: Re: [PHP] nested, referenced foreach & implicit current array pointer issues
- Next by thread: Re: Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
- Index(es):
Relevant Pages
|