Being the colleague Sean refered to in his first post I thought I
might weigh in.
While I agree that once I looked at the base case that Sean worked out
of my code the problem didn't take too long to recognize, that's not
where I first experianced the problem. Problems first rear their head
deep
It *has* to be an E_STRICT because it's something related to language
and possible semantic errors. E_NOTICE is not for that.
Isn't it the same as the following?
[EMAIL PROTECTED]:~$ php5 -derror_reporting=2047 -r '$a=$b;'
Notice: Undefined variable: b in Command line code on line 1
Hi,
A week or two ago, a colleague asked me about a strange behaviour he
experienced, with seemingly-duplicate data within a foreach block. Upon
further examination, we determined that this was caused by assigning to
a referenced variable:
?php
$i = array('zero','one','two');
foreach ($i AS $j)
try:
?php
$i = array('zero','one','two');
foreach ($i AS $j) {}
unset($j) // this
foreach ($i AS $j) {
echo $j . ;
}
?
it's known behavior. may app rely on this.
However, upon further discussion, a number of us agreed that it would be
pertinent to raise an E_NOTICE when foreach assigns to a pre-existing
reference target. Certainly, the behaviour demonstrated above is
non-obvious, and contrary to the normal PHP way (simplicity).
Developers, at least in
Can we throw an E_NOTICE when foreach targets a reference? (The other
there's many way to use reference, not only in foreach. don't do
reference unless u know it's really needed.
Sean's not so much referring to his own problem as (like you said) the
solution is a fairly simple matter of
Sean's not so much referring to his own problem as (like you said) the
solution is a fairly simple matter of following strict coding practices.
yeah, i see.
but...
when foreach assigns to a pre-existing
reference target
it's not the problem of the second foreach, any usage of $j after the
1st
it's not the problem of the second foreach, any usage of $j after the
1st foreach as $j will hurt
Yes. I thought it was clear that I understand this. I guess not.
My point is that foreach is doing something that isn't immediately
obvious. The same is true of your for loop, but to a lesser
Sean Coates wrote:
it's not the problem of the second foreach, any usage of $j after the
1st foreach as $j will hurt
Yes. I thought it was clear that I understand this. I guess not.
My point is that foreach is doing something that isn't immediately
obvious. The same is true of your for loop,
On Mon, 6 Mar 2006, Sara Golemon wrote:
Can we throw an E_NOTICE when foreach targets a reference? (The other
there's many way to use reference, not only in foreach. don't do
reference unless u know it's really needed.
Sean's not so much referring to his own problem as (like you said)
10 matches
Mail list logo