Forums / Upgrading to 1.5.x / v1.58a with php 8.1, PHP Warning and PHP Deprecated

v1.58a with php 8.1, PHP Warning and PHP Deprecated

Views: 3,151

Results 1 to 2 of 2
6 Jun 2024, 2:04 PM
#1
njcyx avatar

njcyx

Zen Follower

Join Date:
Apr 2019
Posts:
376
Plugin Contributions:
0

v1.58a with php 8.1, PHP Warning and PHP Deprecated

Greetings. My site just upgraded from 1.57d to 1.58a, and upgraded the php version to 8.1 (finally). I received the following warning from the back end over last night. It seems the following warnings are intermittent, not sure how to trigger it.

Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(57): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "contactname" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 57.

Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(58): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "email" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 58.

Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(59): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "telephone" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 59.

Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(60): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "enquiry" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 60.

Request URI: /index.php?main_page=checkout_success&action=create_account, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/checkout_success/header_php_guest.php(28): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "email_format" in public_html/includes/modules/pages/checkout_success/header_php_guest.php on line 28.

Here is my temp solution for the warning above. Change code from

    $name = zen_db_prepare_input($_POST['contactname']);
    $email_address = zen_db_prepare_input($_POST['email']);
    $telephone = zen_db_prepare_input($_POST['telephone']);
    $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));

To:

    $name = zen_db_prepare_input(($_POST['contactname'] ?? ''));
    $email_address = zen_db_prepare_input(($_POST['email'] ?? ''));
    $telephone = zen_db_prepare_input(($_POST['telephone']?? ''));
    $enquiry = zen_db_prepare_input(strip_tags(($_POST['enquiry']?? '')));

Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/classes/observers/class.google_recaptcha.php(40): zen_debug_error_handler()
#1 public_html/includes/classes/traits/NotifierManager.php(87): google_recaptcha->update()
#2 public_html/includes/modules/pages/ask_a_question/header_php.php(64): base->notify()
#3 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "g-recaptcha-response" in public_html/includes/classes/observers/class.google_recaptcha.php on line 40.

It is related to google google_recaptcha plug-in. Similarly, change code from

$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);

To:

$resp = $recaptcha->verify(($_POST['g-recaptcha-response'] ?? ''), $_SERVER['REMOTE_ADDR']);

Request URI: /index.php?main_page=checkout_success&action=create_account, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/checkout_success/header_php_guest.php(28): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "email_format" in public_html/includes/modules/pages/checkout_success/header_php_guest.php on line 28.

It is related to OPC 2.5.1. Change code from

$email_format = $_POST['email_format'];

To

$email_format = ($_POST['email_format'] ?? '');

Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 [internal function]: zen_debug_error_handler()
#1 public_html/includes/functions/functions_email.php(720): substr_count()
#2 public_html/includes/modules/pages/ask_a_question/header_php.php(66): zen_validate_email()
#3 public_html/index.php(35): require('...')
--> PHP Deprecated: substr_count(): Passing null to parameter #1 ($haystack) of type string is deprecated in public_html/includes/functions/functions_email.php on line 720.

Change code from

if (substr_count($email,'@') != 1) return false;

To

if (substr_count(($email ?? ''),'@') != 1) return false;

If you have a better idea to solve those warnings, please let me know.

11 Jun 2024, 9:00 PM
#2
njcyx avatar

njcyx

Zen Follower

Join Date:
Apr 2019
Posts:
376
Plugin Contributions:
0

Re: v1.58a with php 8.1, PHP Warning and PHP Deprecated

More warnings and fixes:

Request URI: /ipn_main_handler.php?type=ec&token=EC-xxxx&PayerID=xxxx, IP address: xxxx, Language id 1
#0 /includes/classes/OnePageCheckout.php(2379): zen_debug_error_handler()
#1 /includes/classes/observers/class.checkout_one_observer.php(625): OnePageCheckout->setPayPalAddressCreationBypass()
#2 /includes/classes/traits/NotifierManager.php(87): checkout_one_observer->update()
#3 /includes/modules/payment/paypalwpp.php(2165): base->notify()
#4 /includes/modules/payment/paypalwpp.php(2012): paypalwpp->ec_step2_finish()
#5 /ipn_main_handler.php(85): paypalwpp->ec_step2()
--> PHP Warning: Undefined array key "address_format_id" in /includes/classes/OnePageCheckout.php on line 2379.

Change from

$this->tempAddressValues['ship']['format_id'] = $country_info['address_format_id'];

to

$this->tempAddressValues['ship']['format_id'] = ($country_info['address_format_id'] ?? '');

PHP Warning: Undefined array key "languages_id" in /includes/extra_configures/enable_error_logging.php on line 84

Change from

$language_info = ', Language id ' . $_SESSION['languages_id'];

to

$language_info = ', Language id ' . ($_SESSION['languages_id'] ?? '');

Request URI: /ipn_main_handler.php, IP address: xxxx, Language id
#0 /includes/modules/payment/paypal/paypal_functions.php(48): zen_debug_error_handler()
#1 /includes/init_includes/init_paypal_ipn_sessions.php(34): ipn_get_stored_session()
#2 /includes/autoload_func.php(40): require_once('/...')
#3 /includes/application_top.php(237): require('/...')
#4 /ipn_main_handler.php(141): require('/...')
--> PHP Warning: Undefined array key 1 in /includes/modules/payment/paypal/paypal_functions.php on line 48.
and
--> PHP Warning: Undefined array key 1 in /includes/modules/payment/paypal/paypal_functions.php on line 55.

Change from (based on version 1.5.8a, only one spot needs to be changed)

if (!is_array($session_stuff)) {

to (referring to version 2.0.0rc-1)

if (!is_array($session_stuff) || !isset($session_stuff[1])) {

Request URI: /ipn_main_handler.php, IP address: xxxx, Language id
#0 [internal function]: zen_debug_error_handler()
#1 /includes/classes/db/mysql/query_factory.php(177): mysqli_real_escape_string()
#2 /includes/classes/db/mysql/query_factory.php(562): queryFactory->prepare_input()
#3 /includes/classes/db/mysql/query_factory.php(513): queryFactory->getBindVarValue()
#4 /includes/modules/payment/paypal/paypal_functions.php(48): queryFactory->bindVars()
#5 /includes/init_includes/init_paypal_ipn_sessions.php(34): ipn_get_stored_session()
#6 /includes/autoload_func.php(40): require_once('/...')
#7 /includes/application_top.php(237): require('/...')
#8 /ipn_main_handler.php(141): require('/...')
--> PHP Deprecated: mysqli_real_escape_string(): Passing null to parameter #2 ($string) of type string is deprecated in /includes/classes/db/mysql/query_factory.php on line 177.

Change from

return mysqli_real_escape_string($this->link, $string);

To

return mysqli_real_escape_string($this->link, ($string ?? ''));

Request URI: /index.php?main_page=checkout_process, IP address: xxxx, Language id 1
#0 /includes/modules/payment/paypaldp.php(1989): zen_debug_error_handler()
#1 /includes/modules/payment/paypaldp.php(966): paypaldp->_errorHandler()
#2 /includes/classes/payment.php(288): paypaldp->before_process()
#3 /includes/modules/checkout_process.php(98): payment->before_process()
#4 /includes/modules/pages/checkout_process/header_php.php(13): require('/...')
#5 /index.php(35): require('/...')
--> PHP Warning: Undefined variable $error_occurred in /includes/modules/payment/paypaldp.php on line 1989.

Referring link: https://github.com/zencart/zencart/pull/1089/files

Change from:

$this->_doDebug('PayPal Error Log - before_process() - DP', "In function: before_process() - Direct Payment \r\nDid first contact attempt return error? " . ($error_occurred ? "Yes" : "No") . " \r\n\r\nValue List:\r\n" . str_replace('&',"\r\n", urldecode($doPayPal->_sanitizeLog($doPayPal->_parseNameValueList($doPayPal->lastParamList)))) . "\r\n\r\nResponse:\r\n" . urldecode(print_r($response, true)));

To:

$this->_doDebug('PayPal Error Log - before_process() - DP', "In function: before_process() - Direct Payment \r\n\r\nValue List:\r\n" . str_replace('&',"\r\n", urldecode($doPayPal->_sanitizeLog($doPayPal->_parseNameValueList($doPayPal->lastParamList)))) . "\r\n\r\nResponse:\r\n" . urldecode(print_r($response, true)));

Request URI: /admin/index.php?cmd=specials&search=xxxx&sID=xxxx, IP address: xxxx, Language id 1
#0 /admin/specials.php(452): zen_debug_error_handler()
#1 /admin/index.php(11): require('/...')
--> PHP Warning: Undefined array key "page" in /admin/specials.php on line 452.

Request URI: /admin/index.php?cmd=salemaker&action=insert, IP address: xxxx, Language id 1
#0 /admin/salemaker.php(97): zen_debug_error_handler()
#1 /admin/index.php(11): require('/...')
--> PHP Warning: Undefined array key "page" in /admin/salemaker.php on line 97.

Similar fix. Change from

zen_redirect(zen_href_link(FILENAME_SALEMAKER, 'page=' . $_GET['page'] . '&sID=' . $_POST['sID']));

to

zen_redirect(zen_href_link(FILENAME_SALEMAKER, 'page=' . ($_GET['page'] ?? '') . '&sID=' . $_POST['sID']));