Quote Originally Posted by lat9 View Post
Actually, the following statement is the something that's between the function definition and the first usage.
Code:
 $aimdata->fields = array();
Since it's $aimdata->fields that's being assigned that empty array, that's where the issue arises because $aimdata is not an object. I do agree that the change could be simplified as follows to "prepare" for the use of that required handling:
Code:
function admin_notification($zf_order_id) {
    global $db;
    $output = '';
    $aimdata = new stdClass();
    $aimdata->fields = array();
    require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
    return $output;
  }
We've said the same thing.

Note: an if statement/conditional test was not used/needed before the first $aimdata-> and that the assignment within the previous if statement was still used/needed.

Although no question was asked nor a statement directly made of not understanding the textual description, the following expanded and broken down information is provided. In my opinion likely to still be misunderstood, but please ask away about whatever is confusing or not understood or where I have possibly used incorrect terminology.

Function declaration:
Code:
function admin_notification($zf_order_id)
Parameter(s) (none are $aimdata):
Code:
$zf_order_id
Global(s) (none include $aimdata):
Code:
    global $db;
First usage of $aimdata->:
Code:
 $aimdata->fields = array();
The code expected that contains the unnecessary if condition:
Code:
function admin_notification($zf_order_id) {
    global $db;
    $output = '';
    if (!isset($aimdata)) {
      $aimdata = new stdClass();
    }
    $aimdata->fields = array();
    require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
    return $output;
  }
Considered unnecessary because the if statement evaluates like this all of the time:
Code:
function admin_notification($zf_order_id) {
    global $db;
    $output = '';
    if (true) {
      $aimdata = new stdClass();
    }
    $aimdata->fields = array();
    require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
    return $output;
  }
And therefore could be written without the if statement as described previously in text, as provided above (ie lat9's post) and as DrByte indicated in the rework of ZC to elimate the error/improve the code.
Code:
function admin_notification($zf_order_id) {
    global $db;
    $output = '';
    $aimdata = new stdClass();
    $aimdata->fields = array();
    require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
    return $output;
  }
Again though as discussed if there have been other edits to the code above the first use of $aimdata->, then the if statement may be necessary. But there has not been any indication of such. If there has been such an edit, it would be beneficial to know about so that one can evaluate whether the if statement is in fact necessary or not.