-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#53405 bugfix: current in foreach (by ptrofimov,dmkuznetsov) #113
Conversation
Could you please add a test for this bugfix? |
ping @ptrofimov |
ping again @ptrofimov |
@lstrojny Oh, sorry. I thought everybody forgot about this pull request)) I'll add tests in few days. |
Nope. We never forget (alright, sometimes). |
I don't think that this change is right. I'm pretty sure that the function was intentionally marked This will change the behavior and it's unclear to me what behavior is the right one. At least this needs a bit more explanation. If this is about making current()/key() independent of foreach() then this will only help in a limited way (esp when foreach-by-ref or foreach-over-ref is used). I have a patch that properly decouples foreach from the internal array pointer, but that's a rather more heavy change. |
@nikic thanks for the explanation. Do you mind closing it and open a different issue for your refactoring? |
Well, the problem was that the code $a = array(1, 2, 3);
foreach ($a as $i) {
var_dump(current($a));
} should give 1,1,1. But it gives 2,2,2. After this patch it gave 1,1,1. Well, perhaps, we should close the issue(( |
I don't think it should be closed until its fixed. Has the same issue once it was a mess because it gives different results http://3v4l.org/sBDjl#v430. Can you also look at http://stackoverflow.com/a/14849560/1226894 and confirm how a function affect current output when working with foreach |
@lstrojny What I have was basically a try to improve performance by avoiding the array copy in foreach; the decoupling from the internal array pointer was more of a sideeffect. And as I didn't yet see performance benefits for "real" code (only in artificial benchmarks) I'm not sure we want to do that change. |
Closing as this subject is debatted against PHP7 actually, with a more detailed patch. |
#53405 bugfix: current in foreach (by ptrofimov,dmkuznetsov)