[Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings
I have had a couple of these debug warnings with PHP 7.1. No doubt there will be more...
1) in advanced_search_result_header.php
I changed
Quote:
$rate = $currencies->get_value($_SESSION['currency']);
if ($rate) {
$pfrom = $_GET['pfrom'] / $rate;
$pto = $_GET['pto'] / $rate;}
to
Quote:
$rate = $currencies->get_value($_SESSION['currency']);
if ($rate) {
$pfrom = (float)$_GET['pfrom'] / $rate;//steve added float for PHP 7 warning
$pto = (float)$_GET['pto'] / $rate;//steve added float for PHP 7 warning
}
Note this was provoked by an url like this
SHOP_ROOT/index.php?main_page=advanced_search_result&keyword=asas&search_in_description=1& categories_id=&inc_subcat=1&manufacturers_id=&pfrom=&pto=&dfrom=&dto=
2) functions_taxes.php
I changed
Quote:
// Calculates Tax rounding the result function
zen_calculate_tax($price, $tax = 0) {
$price = $price;
$tax = $tax;
//eof global $currencies;
return $price * $tax / 100;
}
to
Quote:
// Calculates Tax rounding the result
function zen_calculate_tax($price, $tax = 0) {
$price = (float)$price; //steve added float for PHP 7 warning
$tax = (float)$tax; //steve added float for PHP 7 warning
//eof global $currencies;
return $price * $tax / 100;
}
Re: PHP Warning: A non-numeric value encountered... - PHP 7 warnings
confirmed the problem and solution for advanced_search.
PHP Warning: A non-numeric value encountered... categories_ul_generator.php
V1.5.5e
PHP v7.1.1
Stirling Grand Template
css_js_loader
Dynamic Price Updater
One page checkout
SBA
User tracking
Zen Magnific
CEON
Elastislide & Responsive Image Gallery
Dynamic Attr. Filter
This might be the place for these errors so,
I have a similar debug error
PHP Warning: A non-numeric value encountered in C:\mylocalserver\www\mydomain.co.uk\includes\classes\categories_ul_generator.php on line 58
said line is:
PHP Code:
$result = sprintf($this->parent_group_start_string, ($submenu==true) ? ' class="level'. ($level+1) . '"' : '' );
error remedied, with no obvious effect, by changing to:
PHP Code:
$result = sprintf($this->parent_group_start_string, ($submenu==true) ? ' class="level'. ($level) . '"' : '' );
it would be good to know the actual effect that had. The line comes from this block:
PHP Code:
function buildBranch($parent_id, $level = 0, $submenu=true, $parent_link='')
{
$result = sprintf($this->parent_group_start_string, ($submenu==true) ? ' class="level'. ($level+1) . '"' : '' );
if (($this->data[$parent_id])) {
foreach($this->data[$parent_id] as $category_id => $category) {
$category_link = $parent_link . $category_id;
if (($this->data[$category_id])) {
$result .= sprintf($this->child_start_string, ($submenu==true) ? ' class="submenu"' : '');
} else {
$result .= sprintf($this->child_start_string, '');
}
$result .= str_repeat($this->spacer_string, $this->spacer_multiplier * 1) . '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $category_link) . '">';
$result .= $category['name'];
$result .= '</a>';
if (($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
$result .= $this->buildBranch($category_id, $level+1, $submenu, $category_link . '_');
}
$result .= $this->child_end_string;
}
}
$result .= $this->parent_group_end_string;
return $result;
}
I have the original line 58 in
ZC v1.5.4/PHP v5.6.5
ZC v1.5.5a/PHP v5.6.5
both of which worked fine, I suspect it might be a PHP 7 issue.
What do you think?
Re: PHP Warning: A non-numeric value encountered... categories_ul_generator.php
don't like it. changes what the function is doing. i would change the line to:
PHP Code:
$result = sprintf($this->parent_group_start_string, ($submenu==true) ? ' class="level'. ((float)$level+1) . '"' : '' );
note that this is a warning, and php 7 now issues warnings when attempting arithmetic operations on strings or null values. while it is a change i would hardly call it an issue with php7.
best.
Re: PHP Warning: A non-numeric value encountered... categories_ul_generator.php
That's great, thank you for clarifying that.
Edit: fixed that, more of the same at:
..\includes\functions\functions_taxes.php on line 172.
torvista was right.
Re: PHP Warning: A non-numeric value encountered... - PHP 7 warnings
be careful w taxes fix. i think this is the recommended fix:
https://github.com/zencart/zencart/pull/1437/files
Re: PHP Warning: A non-numeric value encountered... categories_ul_generator.php
Quote:
Originally Posted by
simon1066
That's great, thank you for clarifying that.
Edit: fixed that, more of the same at:
..\includes\functions\functions_taxes.php on line 172.
torvista was right.
The CORRECT way to fix this one is shown here: #18 ... everything else is a bandage.
Re: PHP Warning: A non-numeric value encountered... categories_ul_generator.php
Thank you, I had forgotten to look at the bug fixes thread.
Re: PHP Warning: A non-numeric value encountered... categories_ul_generator.php
Had a similar error on a client's site (ZC 1.5.5e) asf:
Quote:
[19-Oct-2017 16:33:21 UTC] PHP Warning: A non-numeric value encountered in includes/modules/pages/advanced_search_result/header_php.php on line 368
The recommended fix
https://github.com/zencart/zencart/pull/1437/files
made no difference at all.
So, I applied torvista's suggestion which appears to work. Not saying it is the *correct* fix but the cart now runs without errors.
Re: PHP Warning: A non-numeric value encountered... categories_ul_generator.php
Quote:
Originally Posted by
frank18
Had a similar error on a client's site (ZC 1.5.5e) asf:
The recommended fix
https://github.com/zencart/zencart/pull/1437/files
made no difference at all.
So, I applied torvista's suggestion which appears to work. Not saying it is the *correct* fix but the cart now runs without errors.
the recommended fix deals with tax problems, not with advanced_search_results....
your error log clearly states an issues with advanced search results, which is a different fix than the tax one. so i would recommend applying them both.
i find @torvista s work solid and agree with most things he brings up; certainly in this case, it does address your issue....
best.