Forums / Bug Reports / [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

[Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Locked

Views: 18,578

Results 1 to 20 of 39
This thread is locked. New replies are disabled.
1 Aug 2017, 9:58 AM
#1
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

[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

$rate = $currencies->get_value($_SESSION['currency']);
if ($rate) {
$pfrom = $_GET['pfrom'] / $rate;
$pto = $_GET['pto'] / $rate;}

to

$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=

  1. functions_taxes.php

I changed

// Calculates Tax rounding the result function
zen_calculate_tax($price, $tax = 0) {
$price = $price;
$tax = $tax;
//eof global $currencies;
return $price * $tax / 100;
}

to

// 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;
}

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

1 Aug 2017, 2:30 PM
#2
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

confirmed the problem and solution for advanced_search.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

20 Aug 2017, 4:53 PM
#3
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

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:

 $result = sprintf($this->parent_group_start_string, ($submenu==true) ? ' class="level'. ($level+1) . '"' : '' );

error remedied, with no obvious effect, by changing to:

$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:

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?****

Simon

20 Aug 2017, 5:07 PM
#4
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

don't like it. changes what the function is doing. i would change the line to:

$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.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

20 Aug 2017, 5:38 PM
#5
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

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.

Simon

20 Aug 2017, 6:29 PM
#6
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: [Done v1.5.6] 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

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

20 Aug 2017, 6:29 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Aug 2017, 6:58 AM
#8
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Thank you, I had forgotten to look at the bug fixes thread.

Simon

20 Oct 2017, 1:06 AM
#9
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Had a similar error on a client's site (ZC 1.5.5e) asf:

[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.

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

20 Oct 2017, 1:29 AM
#10
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

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.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

20 Oct 2017, 1:38 AM
#11
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

carlwhat:

..... so i would recommend applying them both.

Yep, did just that.

carlwhat:

i find @torvista s work solid and agree with most things he brings up; certainly in this case, it does address your issue....

best.

Absolutely, fully agree hence I had no hesitation applying his suggestion.

Cheers

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

11 Dec 2017, 4:27 PM
#12
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Scenario:
start to add a new product
select "Product Priced by Attributes: - Yes"
Leave price blank/0
Other fields do not matter.

Insert product.
Debug log generated:

[11-Dec-2017 17:17:48 Europe/Madrid] Request URI: /zc155e_vanilla/admin1/product.php?cPath=1_17&product_type=1&pID=183&action=new_product_preview&page=1, IP address: 127.0.0.1
#1 currencies->format() called at blah-blah\public_html\zc155e_vanilla\admin1\includes\modules\product\preview_info.php:56]
#2 require(blah-blah\public_html\zc155e_vanilla\admin1\includes\modules\product\preview_info.php) called at [blah-blah\public_html\zc155e_vanilla\admin1\product.php:145]

[11-Dec-2017 17:17:48 Europe/Madrid] PHP Warning: A non-numeric value encountered in blah-blah\public_html\zc155e_vanilla\includes\classes\currencies.php on line 50

Line 50 is pretty meaty so I'll leave this for those who seem to enjoy these challenges.......

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

11 Dec 2017, 4:55 PM
#13
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

torvista:

Scenario:
start to add a new product
select "Product Priced by Attributes: - Yes"
Leave price blank/0
Other fields do not matter.

Insert product.
Debug log generated:

Line 50 is pretty meaty so I'll leave this for those who seem to enjoy these challenges.......

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

The "Product Priced by Attributes" setting is a red-herring and doesn't matter; the root cause of the debug-log is the fact that the product's price is not entered so it's an empty string ('') and thus non-numeric so that PHP 7.0+'s variable-type-checking steps in.

/admin/includes/modules/product/preview_info.php should ensure that the price value supplied to the currency class is numeric, i.e. an update to line 56 of that file from the ZC 1.5.5e distribution:
<td class="pageHeading" align="right"><?php echo $currencies->format([B][B](float)[/B][/B]$pInfo->products_price) . ($pInfo->products_virtual == 1 ? '<span class="errorText">' . '<br />' . TEXT_VIRTUAL_PREVIEW . '</span>' : '') . ($pInfo->product_is_always_free_shipping == 1 ? '<span class="errorText">' . '<br />' . TEXT_FREE_SHIPPING_PREVIEW . '</span>' : '') . ($pInfo->products_priced_by_attribute == 1 ? '<span class="errorText">' . '<br />' . TEXT_PRODUCTS_PRICED_BY_ATTRIBUTES_PREVIEW . '</span>' : '') . ($pInfo->product_is_free == 1 ? '<span class="errorText">' . '<br />' . TEXT_PRODUCTS_IS_FREE_PREVIEW . '</span>' : '') . ($pInfo->product_is_call == 1 ? '<span class="errorText">' . '<br />' . TEXT_PRODUCTS_IS_CALL_PREVIEW . '</span>' : '') . ($pInfo->products_qty_box_status == 0 ? '<span class="errorText">' . '<br />' . TEXT_PRODUCTS_QTY_BOX_STATUS_PREVIEW . '</span>' : '') . ($pInfo->products_priced_by_attribute == 1 ? '<br />' . zen_get_products_display_price($_GET['pID']) : ''); ?></td> ```

I'll note that the issue remains on the current ZC 1.5.6 repository.

11 Dec 2017, 8:57 PM
#14
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

That was easy.. (for me)!
Thanks!

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

10 Jan 2018, 9:19 AM
#15
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Hi
I'm getting this warnings with 7.1
I did fix the categories_ul_generator with (int) .... now I was about to fix the taxes, and I understood I could be here doing this all day, so I search for a solution in the forum.

But I see the use of (float) also.... plus the github fix for taxes
Does the zc 1.55f fix this issues , or if not , is it "safer" to use float where ever I get this warnings ?

Thanks

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

12 Jan 2018, 1:24 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

PHP 7.2 support is NOT built-in to v1.5.5f.
But here's a list of the changes required to adapt it: https://github.com/zencart/zencart/pull/1582/files

All of these ARE built-in to v1.5.6

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Jan 2018, 8:52 AM
#17
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

One other issue that I'm facing is :

Uncaught Error: Cannot use string offset as an array in /home/xxx/public_html/includes/modules/tpl_pb/category_row.php:39

But, this Error only occurs in the online server with 7.1.13
On my local xampp 7.1.12 it doesn't

This is one, another it's driving me crazy, because it works in my local machine and it doesn't on the online server, and I even don't know what to ask...

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

12 Jan 2018, 9:36 AM
#18
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Uncaught Error: Cannot use string offset as an array in /home/xxx/public_html/includes/modules/tpl_pb/category_row.php:39

After all it does occur in my local machine, but it's related to breadcrumb. And I've update php to 7, zencart to 155f, Ceon URI to php7, and now I'm lost.
Big mistake.
But probably it's related to CEON.... or not.

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

12 Jan 2018, 11:53 AM
#19
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

mesnitu:

Uncaught Error: Cannot use string offset as an array in /home/xxx/public_html/includes/modules/tpl_pb/category_row.php:39

> 
> After all it does occur in my local machine, but it's related to breadcrumb. And I've update php to 7, zencart to 155f, Ceon URI to php7, and now I'm lost. 
> Big mistake.
> But probably it's related to CEON.... or not.

The Ceon URI Mapping that has been updated to support php 7 addresses the breadcrumb issue and this error has not otherwise been seen. The fact that this file is in a template override directory implies it has been modified in some way to support the template (not a modification made by Ceon URI Mapping), so it would make more sense to provide the code at, around, and before line 39 to try to identify what modification has been made to cause an attempt to use a string offset as an array.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Jan 2018, 12:18 PM
#20
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: [Done v1.5.6] PHP Warning: A non-numeric value encountered... - PHP 7 warnings

Thanks!!!
Less one problem !
The issue was on the modify file. It had this
$list_box_contents ='';

instead of this
$list_box_contents = array();

... don't know why, probably some update that I miss.
Now it ok !

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison