?
avatar ggppdk
ggppdk
20 Dec 2014

Steps to reproduce the issue

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

https://bugs.php.net/bug.php?id=29992

avatar ggppdk ggppdk - open - 20 Dec 2014
avatar webmasterab
webmasterab - comment - 21 Dec 2014

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.
avatar zero-24 zero-24 - change - 22 Dec 2014
Status New Information Required
avatar zero-24
zero-24 - comment - 22 Dec 2014

Moving to Information Required

maybe @ggppdk can provide some examples and/or do a pull request against staging


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5482.
avatar ggppdk
ggppdk - comment - 22 Dec 2014

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.

avatar zero-24
zero-24 - comment - 23 Dec 2014

@ggppdk please have a look here:
#5493
#5494
#5495
#5496

avatar zero-24 zero-24 - change - 23 Dec 2014
Status Information Required Closed
avatar zero-24
zero-24 - comment - 23 Dec 2014

Closing here as we have PRs to fix this issue. I hope you can review my PRs @ggppdk Thanks. :smile:


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5482.
avatar jissues-bot
jissues-bot - comment - 23 Dec 2014

Set to "closed" on behalf of @zero-24 by The JTracker Application at issues.joomla.org/joomla-cms/5482

avatar jissues-bot jissues-bot - change - 23 Dec 2014
Closed_Date 0000-00-00 00:00:00 2014-12-23 00:03:37
avatar jissues-bot jissues-bot - close - 23 Dec 2014
avatar zero-24 zero-24 - close - 23 Dec 2014
avatar zero-24 zero-24 - change - 7 Jul 2015
Labels Added: ?

Add a Comment

Login with GitHub to post a comment