In many places inside Joomla code, there are loops by reference
e.g.
foreach($items as &$item) {
// do something
}
at the end of these loop the --reference-- variable should be unset:
e.g.
unset($item);
otherwise any assignment of it will damage the last pointed variable
example of code that will damage last pointed value:
foreach($items as &$item) {
// do something
}
foreach($items as $item) {
// do something
}
The above will cause the 1st element of the array to overwrite the last element of the array
Status | New | ⇒ | Information Required |
Moving to Information Required
maybe @ggppdk can provide some examples and/or do a pull request against staging
Inside Joomla CMS code , it is done mostly in component/module/etc template files
if you do a search for text "as &" you will find 100-150+ such loops, none of them unsets the variable after the loop.
So despite this being easy to address, it involves many places. And the fact that is inside template files is not good because you have people making a Joomla template override and not being aware that there of this, they could destroy last element of the items array, if they decide to do:
foreach($items as $item) {
}
Again, this is not a bug, just a very dangerous practice not to unset the variable that references the array of the loop.
-- there are legitimate reasons to have a reference when you are searching for a value, and you break out of loop when you find it. So all loops that do not do a search and break-loop, should unset the variable.
Status | Information Required | ⇒ | Closed |
Closing here as we have PRs to fix this issue. I hope you can review my PRs @ggppdk Thanks.
Set to "closed" on behalf of @zero-24 by The JTracker Application at issues.joomla.org/joomla-cms/5482
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-12-23 00:03:37 |
Labels |
Added:
?
|
You can also specify which files it is.
Then we can test this.
To make a pull of reqeust
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5482.