zendoctor Posted March 28, 2010 Share Posted March 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/ Share on other sites More sharing options...
zendoctor Posted March 29, 2010 Author Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/#findComment-1033385 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2010 Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/#findComment-1033388 Share on other sites More sharing options...
zendoctor Posted March 29, 2010 Author Share Posted March 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/#findComment-1033395 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2010 Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/#findComment-1033400 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2010 Share Posted March 29, 2010 Could you post a link to this mod so that someone could get and see all the code at one time? Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/#findComment-1033402 Share on other sites More sharing options...
zendoctor Posted March 29, 2010 Author Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196805-php-fatal-error-call-to-a-member-function-getauthcode-on-a-non-object/#findComment-1033588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.