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);
}
?>
Call to a member function call() on a non-object
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Call to a member function call() on a non-object
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);
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Call to a member function call() on a non-object
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]);
Last edited by rugarai on Thu Dec 30, 2010 6:46 pm, edited 1 time in total.
Re: Call to a member function call() on a non-object
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);
{
// 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);
Last edited by rugarai on Thu Dec 30, 2010 6:45 pm, edited 1 time in total.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Call to a member function call() on a non-object
You actually instantiate it here
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).
Code: Select all
<?php
$apiclient= new nusoap_client('https://service.dashcs.com/dash-api/soap/emergencyprovisioning/v1?wsdl', true);
$dash_api = new dashcs($apiclient);
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Call to a member function call() on a non-object
Yes but how can I can get this error resolve? Can you give suggestion please? Thanks
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Call to a member function call() on a non-object
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);
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering