Re: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: jochem@xxxxxxxxxxxxx (Jochem Maas)
- Date: Wed, 31 Jan 2007 19:41:42 +0100
speedy wrote:
Hello Martin,
Wednesday, January 31, 2007, 4:50:22 PM, you wrote:
There is nothing wrong with the global keyword, just use $GLOBAL
['arr'] instead to avoid the reference, or create a copy by
assignment.
Yep, already did, 10x for the suggestion. :)
Anyway, I couldn't find this change of behaviour in the foreach in
the changelog, but it seems it have been introduced around may
2005. Maybe is too late to complain, but, now that I know, I think
this behaviour doesn't seem right.
I'd rather see global being equal to $GLOBAL[] in combination with removal
of hidden current pointer from arrays. But I don't have much experience in
designing high-level languages nor did I give a lot of thought about it in the
global picture. :)
regardless of whether your right or wrong from a theoretical/language POV
(I didn't really understand your explaination completely - which is probably
my lack of insight ;-) I would proffer the following:
use of 'global' is bad practice in anything that resembles a complex/real
application. your function has no control over the what $arr is and any piece of
code code change $arr into *anything* at any time.
instead I would suggest that your better off doing one of 2 things:
1. pass in the array to the function explicitly.
2. use a special function that can be called to retrieve the array
from within your example function.
bad advice? I'm open to being corrected :-)
.
- Follow-Ups:
- References:
- nested, referenced foreach & implicit current array pointer issues
- From: speedy
- Re: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: "Martin Alterisio"
- Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: speedy
- Re: Re[2]: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: "Martin Alterisio"
- Re[4]: [PHP] nested, referenced foreach & implicit current array pointer issues
- From: speedy
- nested, referenced foreach & implicit current array pointer issues
- Prev by Date: Re: [PHP] Socket problem plz read.
- Next by Date: [SOLVED] [PHP] return bounced email to specific email address
- Previous by thread: Re[4]: [PHP] nested, referenced foreach & implicit current array pointer issues
- Next by thread: Re: [PHP] nested, referenced foreach & implicit current array pointer issues
- Index(es):
Relevant Pages
|