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 21 to 39 of 39
This thread is locked. New replies are disabled.
12 Jan 2018, 1:42 PM
#21
mc12345678 avatar

mc12345678

Totally Zenned

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

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

mesnitu:

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 !

Good. Yes, php is becoming more stringent about properly identifying how a variable is intended to be used and basically validating that the data is the type expected to use as well as other improvements in the language.

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

15 Jan 2018, 5:20 PM
#22
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

[13-Jan-2018 18:24:07 Europe/Lisbon] PHP Warning:  A non-numeric value encountered in /home/xxxxxx/public_html/includes/modules/pages/advanced_search_result/header_php.php on line 370

The code:

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

I did check on git to see if there were updates on this , but I see no changes.
Should I use a float($rate) ?

Thanks

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

15 Jan 2018, 5:32 PM
#23
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

mesnitu:

[13-Jan-2018 18:24:07 Europe/Lisbon] PHP Warning: A non-numeric value encountered in /home/xxxxxx/public_html/includes/modules/pages/advanced_search_result/header_php.php on line 370

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

I did check on git to see if there were updates on this , but I see no changes.
Should I use a float($rate) ?

Thanks
Nope, the issue there is that the pfrom/pto values, if not set in the form, come back as '' (a non-numeric value). Try the following instead:

$rate = $currencies->get_value($_SESSION['currency']);
if ($rate) {
  $pfrom = ((float)$_GET['pfrom']) / $rate;
  $pto = ((float)$_GET['pto']) / $rate;
}
15 Jan 2018, 6:39 PM
#24
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, I'll try that

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

27 May 2018, 6:02 PM
#25
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,729
Plugin Contributions:
56

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

torvista:

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'];


I added 

   if (!is_numeric($number)) $number = 0;

at line 46 in includes/classes/currencies.php

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

27 May 2018, 8:41 PM
#26
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

I added

if (!is_numeric($number)) $number = 0;

at line 46.

....in classes/currencies.php, to clarify.

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

30 May 2018, 10:37 AM
#27
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,729
Plugin Contributions:
56

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

Seen this a couple of times:

[29-May-2018 07:16:10 America/Los_Angeles] PHP Warning: Creating default object from empty value in admin/product.php on line 224

Fix is pretty straightforward - above line 224 in admin/product.php add

      if (!is_object($pInfo)) $pInfo = new StdClass();

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

20 Jul 2018, 9:40 PM
#28
tamya avatar

tamya

Zen Follower

Join Date:
Feb 2007
Posts:
336
Plugin Contributions:
0

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

I am having the same error
PHP Warning: A non-numeric value encountered in ..../public_html/includes/classes/categories_ul_generator.php on line 73

Line 73 is
$result .= $this->buildBranch($category_id, $level+1, $submenu, $category_link . '');
Coming from the block code
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;

What is the fix for this error?
zen cart 1.5.5f

20 Jul 2018, 10:03 PM
#29
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

TamyA:

I am having the same error
PHP Warning: A non-numeric value encountered in ..../public_html/includes/classes/categories_ul_generator.php on line 73

Line 73 is
$result .= $this->buildBranch($category_id, $level+1, $submenu, $category_link . '');
Coming from the block code
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;

What is the fix for this error?
zen cart 1.5.5f
Change line 58 of the file from:

$level = $level;

To:

$level = (int)$level;

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

20 Jul 2018, 10:13 PM
#30
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

mc12345678:

Change line 58 of the file from:

$level = $level;

> To:
> ```
$level = (int)$level;

Sorry, more than likely will need to add the above at or around line 58 so that $level will be forced to be an integer. In newer php versions it is/will be possible to cast/expect the value to be an integer, but to maintain the existing backwards compatibility the above was the way chosen.

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

21 Jul 2018, 6:07 AM
#31
tamya avatar

tamya

Zen Follower

Join Date:
Feb 2007
Posts:
336
Plugin Contributions:
0

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

mc12345678:

Sorry, more than likely will need to add the above at or around line 58 so that $level will be forced to be an integer. In newer php versions it is/will be possible to cast/expect the value to be an integer, but to maintain the existing backwards compatibility the above was the way chosen.

Thanks a million, it seems to work, so far no error files in the /logs directory, thanks again.

1 Nov 2018, 9:27 AM
#32
doomm avatar

doomm

New Zenner

Join Date:
Sep 2008
Posts:
54
Plugin Contributions:
0

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

Hi, buddies,

after upgrade of my shop to version 1.5.5f and upgrade of PHP to 7.1, I recieved PHP Warning with "a non numeric value encountered" for categories_ul_generator.php and thanks to your updates was able to resolve it fast.

However now I´m stuck,

I recieved the same PHP warning here:

[01-Nov-2018 00:33:02 UTC] Request URI: /index.php?main_page=shopping_cart, IP address: xxx
#1 zones->quote() called at [/home/xxx/public_html/includes/classes/shipping.php:171]
#2 shipping->quote() called at [/home/xxx/public_html/includes/modules/shipping_estimator.php:140]
#3 require(/home/xxx/public_html/includes/modules/shipping_estimator.php) called at [/home/xxx/public_html/includes/templates/responsive_classic/templates/tpl_shopping_cart_default.php:194]
#4 require(/home/xxx/public_html/includes/templates/responsive_classic/templates/tpl_shopping_cart_default.php) called at [/home/xxx/public_html/includes/templates/responsive_classic/common/tpl_main_page.php:171]
#5 require(/home/xxx/public_html/includes/templates/responsive_classic/common/tpl_main_page.php) called at [/home/xxx/public_html/index.php:97]

[01-Nov-2018 00:33:02 UTC] PHP Warning: A non-numeric value encountered in /home/xxx/public_html/includes/modules/shipping/zones.php on line 257

line 257 in zones.php looks like this:

$shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);

any help would be very much appreciated, guys

1 Nov 2018, 11:48 AM
#33
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

Doomm:

Hi, buddies,

after upgrade of my shop to version 1.5.5f and upgrade of PHP to 7.1, I recieved PHP Warning with "a non numeric value encountered" for categories_ul_generator.php and thanks to your updates was able to resolve it fast.

However now I´m stuck,

I recieved the same PHP warning here:

[01-Nov-2018 00:33:02 UTC] Request URI: /index.php?main_page=shopping_cart, IP address: xxx
#1 zones->quote() called at [/home/xxx/public_html/includes/classes/shipping.php:171]
#2 shipping->quote() called at [/home/xxx/public_html/includes/modules/shipping_estimator.php:140]
#3 require(/home/xxx/public_html/includes/modules/shipping_estimator.php) called at [/home/xxx/public_html/includes/templates/responsive_classic/templates/tpl_shopping_cart_default.php:194]
#4 require(/home/xxx/public_html/includes/templates/responsive_classic/templates/tpl_shopping_cart_default.php) called at [/home/xxx/public_html/includes/templates/responsive_classic/common/tpl_main_page.php:171]
#5 require(/home/xxx/public_html/includes/templates/responsive_classic/common/tpl_main_page.php) called at [/home/xxx/public_html/index.php:97]

[01-Nov-2018 00:33:02 UTC] PHP Warning: A non-numeric value encountered in /home/xxx/public_html/includes/modules/shipping/zones.php on line 257

line 257 in zones.php looks like this:

$shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);

any help would be very much appreciated, guys
Looks like in your zones shipping module that for each applicable zone that a value needs to be entered instead of an empty string. So, if there is no handling fee, then a value of 0 should be entered instead of leaving it blank.

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

1 Nov 2018, 12:59 PM
#34
doomm avatar

doomm

New Zenner

Join Date:
Sep 2008
Posts:
54
Plugin Contributions:
0

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

So if I understand it correctly, this should be done from the admin and there is no need to change of the code.

Thank you very much for your time and help.

1 Nov 2018, 2:59 PM
#35
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

Doomm:

So if I understand it correctly, this should be done from the admin and there is no need to change of the code.

Thank you very much for your time and help.
No need, but an improvement in the base code could be made to default to a 0 instead of empty, but typing in a value of 0 should resolve that warning.

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

1 Nov 2018, 4:15 PM
#36
doomm avatar

doomm

New Zenner

Join Date:
Sep 2008
Posts:
54
Plugin Contributions:
0

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

mc12345678:

No need, but an improvement in the base code could be made to default to a 0 instead of empty, but typing in a value of 0 should resolve that warning.

I´m so sorry, I´m not following you (not really a coder, here) and I´m very grateful for your patience.

Could you please direct me where in this php file (zones.php), should I be looking for this empty string?

1 Nov 2018, 4:45 PM
#37
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

Editing the zc155f version of /includes/modules/shipping/zones.php, find:

// class constructor
    function __construct() {
      $this->code = 'zones';
      $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_ZONES_TAX_BASIS;

and add the highlighted fragments:

// class constructor
    function __construct() {
      $this->code = 'zones';
      $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
      $this->sort_order = [B](int)[/B]MODULE_SHIPPING_ZONES_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = [B](int)[/B]MODULE_SHIPPING_ZONES_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_ZONES_TAX_BASIS;

Note that I've also applied that integer "cast" to the tax-class-id, just in case!

1 Nov 2018, 6:29 PM
#38
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

Doomm:

I´m so sorry, I´m not following you (not really a coder, here) and I´m very grateful for your patience.

Could you please direct me where in this php file (zones.php), should I be looking for this empty string?
To address the specific warning message that was presented, the only thing necessary was to enter in a number into the handling fee area for each of the zones and not leave it blank. This entry is performed from admin->modules->shipping->zones.

It appears the code already contains a default value of '0' at least when first installing the additional zone(s).

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

1 Nov 2018, 8:28 PM
#39
doomm avatar

doomm

New Zenner

Join Date:
Sep 2008
Posts:
54
Plugin Contributions:
0

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

mc12345678:

To address the specific warning message that was presented, the only thing necessary was to enter in a number into the handling fee area for each of the zones and not leave it blank. This entry is performed from admin->modules->shipping->zones.

It appears the code already contains a default value of '0' at least when first installing the additional zone(s).

Great, that´s what I did in the first place, but was not sure, if it´s enough.

Thank you very much for your help and understanding,

cheers