Author Topic: Warning: Creating default object from empty value ... in helpers/cart.php  (Read 7374 times)

Thomas Kuschel

  • Jr. Member
  • **
  • Posts: 81
    • LOYTEC electronics GmbH
Greetings!
Description:
When calling the cart module, the function prepareAjaxData() within components/com_virtuemart/helpers/cart.php pops up a warning message, shown in error log too:
 [error] [client 127.0.0.1] PHP Warning:  Creating default object from empty value in /xxxx/joomla/components/com_virtuemart/helpers/cart.php on line 1403, referer: http://loytec.com/en/myloytec/products-documents
This behavior is found in components/com_virtuemart/helpers/cart.php line 1397 ff (latest commit, 6 days ago)

Code: [Select]
//of course, some may argue that the $this->data->products should be generated in the view.html.php, but
//
$this->data->products = array();
$this->data->totalProduct = 0;
$i=0;
My suggestion: adding the following line to create an empty object,
this makes sense:
Code: [Select]
//of course, some may argue that the $this->data->products should be generated in the view.html.php, but
//
$this->data = new stdClass();
$this->data->products = array();
$this->data->totalProduct = 0;
$i=0;
regards,
Thomas Kuschel
http://loytec.com

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10144
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
I added this
Code: [Select]
if(empty($this->data)){
$this->data = new stdClass();
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Thomas Kuschel

  • Jr. Member
  • **
  • Posts: 81
    • LOYTEC electronics GmbH
Hi Milbo,

in that case, it isn't really necessary to query the emptiness of $this->data .

It has nothing to do with robustness nor security. The class do _not_ exists.

All the best

Thomas

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10144
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Imho it can be manipulated by plugins.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/