Jump to content

PHP Fatal error: Call to a member function getAuthCode() on a non-object


Recommended Posts

I am currently trying to debug a website with an error which has suddenly occurred during the past week although I don't believe the code has been changed recently:

 

The error is:  PHP Fatal error:  Call to a member function getAuthCode() on a non-object at Line ....

 

And the relevant (I believe) parts of the code in question is:

 

$parsed_response = array();

$parsed_response['status_code'] = $gateway_output->getStatusCode();
$parsed_response['message'] = $gateway_output->getMessage();
$parsed_response['auth_code'] = $transaction_output_message->getAuthCode();  // This is the line the error points to

class TransactionOutputMessage extends BaseOutputMessage
{
	private $m_szCrossReference;
	private $m_szAuthCode;

        public function getAuthCode()
    { 
        return $this->m_szAuthCode;
    }
//constructor
    public function __construct($szAuthCode)
    {
     	//first calling the parent constructor
        //BaseOutputMessage::__construct($lgepGatewayEntryPoints);
        parent::__construct($lgepGatewayEntryPoints);
       
		$this->m_szAuthCode = $szAuthCode;
    }
}

 

Is there an issue with the code?  Other functions are able to write to the array.

 

Could it be due to a change of PHP version?  I do not know if this has changed recently, current version is 5.2.13.

 

Thanks.

 

 

 

I've spent another few hours on this and not got anywhere.

 

Has anyone seen this error before in a similar scenario, are there any common faults which could cause this error?

 

It is a payment module for Zen Cart, the only other thing I found is a reference to auth_code in the generic order.php file

 

$GLOBALS[$_SESSION['payment']]->auth_code

 

I wasn't sure if that could interfere with the array.  I tried changing the array item to auth_code2 in the 3 places it appears in the payment module but it still crashed with the same error at the same line.

 

I'm quickly running out of ideas, other examples I find of this error look quite different.

The error means that $transaction_output_message is not an instance of a class.

 

There should be a line of code like -

 

$transaction_output_message = new some_class_name();

 

Something is either preventing that line code from being seen at all (it's inside of a conditional statement that is FALSE or inside of an included file that is not being included) or being seen as php code (someone used short opening php tags) or it is not occurring in the same scope as the code where the error is occurring at or something is clearing the $transaction_output_message variable.

 

Setting error_reporting to E_ALL (if it is not already) may help to identify which of those possibilities is causing the problem.

Thanks for the response, I can tell you that line isn't present in the code.

 

function _parseIridiumTransactionResponse($gateway_output, $transaction_output_message) {
$parsed_response = array();

$parsed_response['status_code'] = $gateway_output->getStatusCode();
$parsed_response['message'] = $gateway_output->getMessage();
$parsed_response['auth_code'] = $transaction_output_message->getAuthCode();  // This is the line the error points to

 

$transaction_output_message is an input parameter to a function, for some reason the $gateway_output doesn't cause this problem and likewise is only defined within the function as above, those 2 lines run before the error.

 

Does the fact they are function inputs make any difference, where would a new instance of these be defined?

 

Thanks

You need to keep back-tracking through the code. At the point where that function is called, the second parameter needs to be an instance of the class -

 

_parseIridiumTransactionResponse($gateway_output, $transaction_output_message);

 

There is no guarantee that the variable name being used in the function call is that exact same name.

Problem solved.

 

It turned out to be an admin setting so the module wasn't communicating with the correct port on the payment server.  After speaking with the company who wrote the module and working back through the code checking various variables and placing a few echo/exit statements the source of the problem was traced.

 

The error was stopping the code from executing the section where the instance of TransactionOutputMessage is defined.

 

I expect the client inadvertently did this when they were struggling to install another mod.  It's another few hours experience, now I can continue with the mod I am supposed to be doing.

 

For info it was the Iridium payment module for Zen Cart.

 

Thanks for the help, it certainly got me on the right track to work back through as there are around 6000 lines of code in the module over a few files.  It 's a mod I haven't worked with before.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.