Page 1 of 1

Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 4:52 pm
by rugarai
Hi, I have a script below and I always get the error "Call to a member function call() on a non-object". Can someone help me out how to fix / to deal with this. Please help. Thanks.

<?php
// includes nusoap class
require_once('lib/nusoap.php');
class dashcs
{
public $apiresult = null;
public $apierror = null;
public $apiclient = null;

function __constuct($apiclient)
{
// instantiate the web service api
$this->apiclient = $apiclient;
$this->apiclient->setCredentials("rreffo","95dff6e3","basic");
$this->apierror = $this->apiclient->getError();

if($this->apierror)
{
return false;
}else{
return true;
}
}
//
function dashCallMethod($apimethodname = null,$apiparameters= null)
{
// call the method of the service
if($apiparameters == null || $apiparameters == ''){
$this->apiresult = $this->apiclient->call($apimethodname);
}else{
$this->apiresult = $this->apiclient->call($apimethodname,$apiparameters);
}


if($this->apiclient->fault){
// check for fault
return false;
}else{
// Check for errors
$this->apierror = $this->apiclient->getError();
if ($this->apierror) {
return false;
}else{

return true;
}
}
}
}

// Create objects
$apiclient = new nusoap_client('https://service.sdfdff.com/dash-api/soa ... ng/v1?wsdl', true);
$dash_api = new dashcs($apiclient);
if(!$dash_api)
{
echo $dash_api->apierror;
}

// check first the authentication

if($dash_api->dashCallMethod('getAuthenticationCheck'))
{
echo "API Error: $apierror";
print_r($dash_api->apiresult);
}else{
print_r($dash_api->apiresult);
}


?>

Re: Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 6:05 pm
by social_experiment
;) Kudos on remembering the PHP tags, next time use the PHP Code button first though. It makes reading your code a lot easier.

Methods from inside the class can only be used if an object has been instantiated

Code: Select all

<?php $newObj = new cLass(); ?>

Code: Select all

<?php
 function dashCallMethod($apimethodname = null,$apiparameters= null)
{
// call the method of the service
if($apiparameters == null || $apiparameters == ''){
$this->apiresult = $this->apiclient->call($apimethodname);
}else{
$this->apiresult = $this->apiclient->call($apimethodname,$apiparameters);
}
?>
Im guessing the problem is in this section of code :?

Re: Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 6:20 pm
by rugarai
Yes that is the part of where the error is but I am confused since I already instantiated it via the constructor right?

Code: Select all

	function __constuct(&[b]$apiclient[/b])
	{
		// instantiate the web service api
		$this->apiclient = $apiclient;
		$this->apiclient->setCredentials("sdfsdo","959dfdfse3","basic");
		$this->apierror = $this->apiclient->getError();
		
		if($this->apierror)
		{
			return false;
		}else{
			return true;
		}		
	}

[b]$apiclient [/b]= new nusoap_client('https://service.sdfsdfcs.com/dash-api/soap/emergencyprovisioning/v1?wsdl', true);
$dash_api = new dashcs([b]$apiclient[/b]);

Re: Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 6:21 pm
by rugarai
function __constuct(&$apiclient)
{
// instantiate the web service api
$this->apiclient = $apiclient;
$this->apiclient->setCredentials("rrufsdf","95sdfe3","basic");
$this->apierror = $this->apiclient->getError();

if($this->apierror)
{
return false;
}else{
return true;
}
}

$apiclient= new nusoap_client('https://service.sdfsdf.com/dash-api/soa ... ng/v1?wsdl', true);
$dash_api = new dashcs($apiclient);

Re: Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 6:28 pm
by social_experiment
You actually instantiate it here

Code: Select all

<?php
 $apiclient= new nusoap_client('https://service.dashcs.com/dash-api/soap/emergencyprovisioning/v1?wsdl', true);
 $dash_api = new dashcs($apiclient);
?>
Within the constructor you are simply telling the class that the argument ($apiclient) entered into the constructor is a property of the class ($this->apiclient).

Re: Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 6:44 pm
by rugarai
Yes but how can I can get this error resolve? Can you give suggestion please? Thanks

Re: Call to a member function call() on a non-object

Posted: Thu Dec 30, 2010 7:23 pm
by social_experiment
This is a long shot as i don't know what this method does and have no working knowledge of this class. Make a backup before you try this. Change this method to the following and see what happens. Hth.

Code: Select all

<?php
function dashCallMethod($apimethodname = null,$apiparameters= null)
{
// call the method of the service
if($apiparameters == null || $apiparameters == ''){
$this->apiresult = $this->call($apimethodname);
}else{
$this->apiresult = $this->call($apimethodname,$apiparameters);
}
?>