Zen Cart Logo
Forums / Bug Reports / Possible PHP v7.2 warning

Possible PHP v7.2 warning

Views: 336

Results 1 to 2 of 2
24 Jun 2019, 11:02
#1
simon1066 avatar

simon1066

Totally Zenned

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

Possible PHP v7.2 warning

v1.56b

When viewing the product_info page for a product with a type of Product Music I get this warning with PHP v7.2.10

[24-Jun-2019 11:47:39 Europe/London] Request URI: /MY_CATEGORY/MY_PRODUCT, IP address: 127.0.0.1
#1  require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\media_manager.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\template_default\templates\tpl_modules_media_manager.php:14]
#2  require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\template_default\templates\tpl_modules_media_manager.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\templates\tpl_product_music_info_display.php:193]
#3  require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\templates\tpl_product_music_info_display.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\pages\product_music_info\main_template_vars.php:181]
#4  require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\pages\product_music_info\main_template_vars.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\common\tpl_main_page.php:217]
#5  require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\common\tpl_main_page.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\index.php:97]
--> PHP Warning: count(): Parameter must be an array or an object that implements Countable in D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\media_manager.php on line 69.

From googling, a suggested code change to line 69 of media_manager.php is

change

$zv_product_has_media = (count($za_media_manager) > 0);

to

$zv_product_has_media = (($za_media_manager && count($za_media_manager)) > 0);
24 Jun 2019, 11:33
#2
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Possible PHP v7.2 warning

simon1066:

v1.56b

When viewing the product_info page for a product with a type of Product Music I get this warning with PHP v7.2.10

[24-Jun-2019 11:47:39 Europe/London] Request URI: /MY_CATEGORY/MY_PRODUCT, IP address: 127.0.0.1
#1 require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\media_manager.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\template_default\templates\tpl_modules_media_manager.php:14]
#2 require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\template_default\templates\tpl_modules_media_manager.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\templates\tpl_product_music_info_display.php:193]
#3 require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\templates\tpl_product_music_info_display.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\pages\product_music_info\main_template_vars.php:181]
#4 require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\pages\product_music_info\main_template_vars.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\common\tpl_main_page.php:217]
#5 require(D:\wamp64\www\MY_WEBSITE.co.uk\includes\templates\MY_TEMPLATE\common\tpl_main_page.php) called at [D:\wamp64\www\MY_WEBSITE.co.uk\index.php:97]
--> PHP Warning: count(): Parameter must be an array or an object that implements Countable in D:\wamp64\www\MY_WEBSITE.co.uk\includes\modules\media_manager.php on line 69.

> 
> From googling, a suggested code change to line 69 of media_manager.php is
> 
> change
> ```
$zv_product_has_media = (count($za_media_manager) > 0);

to

$zv_product_has_media = (($za_media_manager && count($za_media_manager)) > 0);

That too could become an issue if $za_media_manager is not set at the point of this test and php is set for strict processing.

A more complete solution could be the following:

$zv_product_has_media = (!empty($za_media_manager) && is_array($zc_media_manager));


The reason being: the first test (!empty) in relation to the goal of this check would be true if the variable is defined and even if set to an array that it has at least one element. The second test (is_array) would be true if the variable is in fact an array.

Any other condition would result in a false result and no debug logs as of at least php 7.3.