Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- From: Rik <luiheidsgoeroe@xxxxxxxxxxx>
- Date: Tue, 31 Jul 2007 02:46:14 +0200
On Tue, 31 Jul 2007 02:38:04 +0200, Jerry Stuckle <jstucklex@xxxxxxxxxxxxx> wrote:
I take this back - the result of the operation is unpredictable. That's because:
$rank[$i] = trim($rank[$i++]);
$rank[$i++]
is evaluated as $rank[$i]. However, when
$rank[$i]
is evaluated, does it use the old or the new version of $i?
This is indeed dubious. Which of the '[' gets evaluated first? Allthough, left-associtivity might indicate the first one should be evaluated first (PHP4 behaviour).
However, for:
$array[$i] = $i++;
Precedence as defined should kick in clearly. The '[' isn't in the table just for show.
The bottom line: don't change a value and use it in the same statement.. Results are unpredictable.
And makes for more readable code indeed. However, if I read the documentation I fully expect the PHP4 result from my example, not the PHP5 one...
--
Rik Wasmus
.
- Follow-Ups:
- Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- From: Jerry Stuckle
- Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- References:
- Does passing an uninitialized array variable initialize it? (PHP 5)
- From: google2006
- Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- From: Jerry Stuckle
- Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- From: Jerry Stuckle
- Does passing an uninitialized array variable initialize it? (PHP 5)
- Prev by Date: Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- Next by Date: Editing Files: Help!
- Previous by thread: Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- Next by thread: Re: Does passing an uninitialized array variable initialize it? (PHP 5)
- Index(es):