VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: Studio 42 on November 09, 2017, 01:15:43 am

Title: router bug Object set as index!
Post by: Studio 42 on November 09, 2017, 01:15:43 am
VM 3.2.4
Check your code arround line 1314 in router.php file :               
Code: [Select]
} else {
static $msg = array();
if(empty($msg[$item])){
vmdebug('my item with empty $link["view"]',$item);
$msg[$item] = 1;
}
$item used to set index is an object ! Lucky, it not break all the online shops.
And adding a static in the else ? I think this not really clear and can give trouble in next releases.

The message i have is :
Quote
Warning: Illegal offset type in isset or empty in /homepages/38/d323638701/htdocs/habitat-ecologique/Joomla3/components/com_virtuemart/router.php on line 1316

Warning: Illegal offset type in /homepages/38/d323638701/htdocs/habitat-ecologique/Joomla3/components/com_virtuemart/router.php on line 1318
Each time the router is called when i'm on PHP debug mode.
Why none control the code with PHP debug mode set to maximum? This is then directly visible.
When you log this errors in php log, you have a 100mo file each day because this.
Title: Re: router bug Object set as index!
Post by: Studio 42 on November 09, 2017, 12:26:43 pm
changing $item to $item->id remove the bug, but static should be moved in the begin of function.
Code: [Select]
} else {
static $msg = array();
if(empty($msg[$item->id])){
vmdebug('my item with empty $link["view"]',$item);
$msg[$item->id] = 1;
}
Title: Re: router bug Object set as index!
Post by: Milbo on November 09, 2017, 14:23:26 pm
Thank you.

Actually it is a kind of "error" message. The static is created here, just to prevent that we see the debug message more than one time. So the creation of the static here is correct imho, even it is dirty.
But setting the object of course is wrong. My suggestion is:
Code: [Select]
static $msg = array();
$id = empty($item->id)? '0': $item->id;
if(empty($msg[$id])){
vmdebug('my item with empty $link["view"]',$item);
$msg[$id] = 1;
}