Author Topic: router bug Object set as index!  (Read 629 times)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3821
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
router bug Object set as index!
« 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.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3821
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: router bug Object set as index!
« Reply #1 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;
}

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9838
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: router bug Object set as index!
« Reply #2 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;
}
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/