Results 1 to 10 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    844
    Plugin Contributions
    0

    Default Re: Creating default object from empty value in modules/payment/authorizenet_aim.php

    I was able to fix this issue by changing line 439 from

    Code:
        $aimdata->fields = array();
    to
    Code:
    if (!isset($aimdata)){ 
         $aimdata = new stdClass();
    }
    $aimdata->fields = array();

  2. #2
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Creating default object from empty value in modules/payment/authorizenet_aim.php

    Quote Originally Posted by bumba000 View Post
    I was able to fix this issue by changing line 439 from

    Code:
        $aimdata->fields = array();
    to
    Code:
    if (!isset($aimdata)){ 
         $aimdata = new stdClass();
    }
    $aimdata->fields = array();
    The if test appears unnecessary when looking at the provided code:
    Code:
    function admin_notification($zf_order_id) {
        global $db;
        $output = '';
        $aimdata->fields = array();
        require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
        return $output;
      }
    Because there is nothing between the function declaration and the first use of $aimdata-> $aimdata will never be set and therefore the code within the if statement will always be executed. I.e. there is no parameter passed to the function assigned to $aimdata, there's no global $aimdata, and no previous assignment.

    Now if that code section is otherwise modified to attempt to pass/operate differently, then it would be helpful to know how it has been edited.

    The solution referenced earlier in the conversation was to do something similar but as described without the if statement.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,965
    Plugin Contributions
    96

    Default Re: Creating default object from empty value in modules/payment/authorizenet_aim.php

    Quote Originally Posted by mc12345678 View Post
    The if test appears unnecessary when looking at the provided code:
    Code:
    function admin_notification($zf_order_id) {
        global $db;
        $output = '';
        $aimdata->fields = array();
        require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
        return $output;
      }
    Because there is nothing between the function declaration and the first use of $aimdata-> $aimdata will never be set and therefore the code within the if statement will always be executed. I.e. there is no parameter passed to the function assigned to $aimdata, there's no global $aimdata, and no previous assignment.

    Now if that code section is otherwise modified to attempt to pass/operate differently, then it would be helpful to know how it has been edited.

    The solution referenced earlier in the conversation was to do something similar but as described without the if statement.
    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;
      }

  4. #4
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Creating default object from empty value in modules/payment/authorizenet_aim.php

    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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,965
    Plugin Contributions
    96

    Default Re: Creating default object from empty value in modules/payment/authorizenet_aim.php

    We might have; I just said it a tad more succinctly.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,447
    Plugin Contributions
    81

    Default Re: Creating default object from empty value in modules/payment/authorizenet_aim.php

    It can be even simpler than that, since the $aimdata variable isn't actually used in the admin_notification file. Doh. Leftover code from back when we hoped AIM would provide it.

    v1.5.6 will have it removed: https://github.com/zencart/zencart/pull/1465/files -- you can make the same changes today, in any version of Zen Cart.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v139h Warning: Creating default object from empty value in shipping_estimator.php
    By split63 in forum Built-in Shipping and Payment Modules
    Replies: 6
    Last Post: 30 Apr 2016, 08:00 PM
  2. v139h Creating default object from empty value (in shipping modules)
    By Phil S in forum General Questions
    Replies: 11
    Last Post: 6 Nov 2015, 06:46 AM
  3. Replies: 20
    Last Post: 7 Dec 2014, 11:29 AM
  4. Replies: 3
    Last Post: 26 Mar 2014, 07:35 PM
  5. Replies: 0
    Last Post: 27 Sep 2012, 11:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg