VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: istvixs on June 20, 2017, 11:42:36 AM

Title: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: istvixs on June 20, 2017, 11:42:36 AM
Hi, my favorite plugin multiple customfields filter for virtuemart, is not fully compatible with php 7. Unfortunately no support, and I need a quick solution. php 7 incompatible code the following:
/plugins/vmcustom/param/param/tmpl/default.php


$values = $viewData->value;
if(count($values) > 0){
$html .='<div class="product-fields-value">';
$html .= '<ul>';
foreach($values as &$v){
if($viewData->ft == 'int'){
$html .= '<li>'.$v->intval.'</li>';
}else{
$html .= '<li>'.JText::_($v->value).'</li>';
}
}unset($v);
$html .= '</ul>';
$html .='</div></div>';
echo $html;
}

int problem, JText works.
Thank you in advance for your help!
Title: Re: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: Ghost on June 20, 2017, 12:35:17 PM
What error are you getting?
Title: Re: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: istvixs on June 20, 2017, 13:04:55 PM
I think foreach cycle php5 and 7 different problem, see attached picture. ROM and OS text values, battery integer values. Integer values empty, no value. Text is ok.
Title: Re: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: Ghost on June 20, 2017, 13:11:20 PM
Can you post var_dump of $values?
Title: Re: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: istvixs on June 20, 2017, 13:56:16 PM
Attached picture php 5.x and php 7.x
Title: Re: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: Milbo on June 20, 2017, 15:01:13 PM

foreach($values as &$v){
if($viewData->ft == 'int'){
$html .= '<li>'.$v->intval.'</li>';
}else{
$html .= '<li>'.JText::_($v->value).'</li>';
}
}
unset($v);



That is shit here. The $v, you unset it outside of the foreach. And it is not wise to use a link/point in the foreach. Better use foreach($values as $k=>$v) and manipulate the elements with $value[$k] instead of the &$v
Title: Re: virtuemart 3rd plugin and extension PHP 7 compatibility
Post by: istvixs on June 20, 2017, 15:07:02 PM
Thanks Boys,

var_dump($value) php5:
array(1) { [0]=> &object(stdClass)#1229 (9) { ["id"]=> NULL ["virtuemart_product_id"]=> string(3) "489" ["virtuemart_custom_id"]=> NULL ["val"]=> string(1) "0" ["intval"]=> string(4) "4100" ["value"]=> NULL ["status"]=> NULL ["published"]=> NULL ["ordering"]=> NULL } }

var_dump($value) php7: nothing