backdrop-contrib / ubercart

A flexible but easy-to-use e-commerce system for Backdrop.
GNU General Public License v2.0
4 stars 9 forks source link

Warning on new order: Deprecated function: function_exists(): Passing null to parameter #1 #494

Closed bugfolder closed 4 months ago

bugfolder commented 5 months ago

When creating a new order, this warning appears:

Deprecated function: function_exists(): Passing null to parameter #1 ($function) of type string is deprecated in uc_order_pane_payment() (line 92 of /mysite/modules/contrib/ubercart/payment/uc_payment/uc_payment_order_pane.inc).

Lines 90–92 are:

      $method = isset($form_state['values']['payment_method']) ? $form_state['values']['payment_method'] : $order->payment_method;
      $func = _uc_payment_method_data($method, 'callback');
      if (function_exists($func) && $details = $func('order-details', $order)) {

The problem is that when an order is newly created, there is no payment method so $method is empty, so $func is NULL.

This should be hardened as follows:

      $method = isset($form_state['values']['payment_method']) ? $form_state['values']['payment_method'] : $order->payment_method;
      $func = _uc_payment_method_data($method, 'callback');
      if (!empty($func) && function_exists($func) && $details = $func('order-details', $order)) {

PR to follow.

laryn commented 4 months ago

Looks good!