Bob's Jellyfish
Bob's Jellyfish

Reputation: 363

class structure using SoapClient

Here is a simplifed I know the code that follows, is not perfectly clean, but for test

Code1:

<?PHP
abstract class webservice
{
    protected  $url;    
    var $clientSoap;

    public function  affectation_base($url_p)
    {
        ini_set('soap.wsdl_cache_enabled',0);
        ini_set('soap.wsdl_cache_ttl',0);

        $this->url=$url_p;
        $clientSoap = new SoapClient('wdsl_adress');
    }

    public function get_fonction()
    {
        $clientSOAP = new SoapClient('wdsl_adress');
        $sestruct = new stdClass();
        $sestruct->value = "test";
        var_dump($clientSOAP->MD5($sestruct));
    }
    abstract protected function getValue();
}



class Webservice_2 extends webservice
{
  public function __construct($url_p)
  {
   $this->affectation_base($url_p); 
  }
  function getValue()
  {} 
}

$wbs = new Webservice_2('wdsl_adress');  
$wbs->getValue();
$wbs->get_fonction();
?>

Code2:

<?PHP
abstract class webservice
{
    protected  $url;    
    var $clientSoap;

    public function  affectation_base($url_p)
    {
        ini_set('soap.wsdl_cache_enabled',0);
        ini_set('soap.wsdl_cache_ttl',0);

        $this->url=$url_p;
        $clientSoap = new SoapClient('wdsl_adress');
    }

    public function get_fonction()
    {
        $sestruct = new stdClass();
        $sestruct->value = "test";
        var_dump($clientSOAP->MD5($sestruct));
    }
    abstract protected function getValue();
}



class Webservice_2 extends webservice
{
  public function __construct($url_p)
  {
   $this->affectation_base($url_p); 
  }
  function getValue()
  {} 
}

$wbs = new Webservice_2('wdsl_adress');  
$wbs->getValue();
$wbs->get_fonction();
?>

"Code1" works

"Code2" doesn't work:

PHP Fatal error: Call to a member function MD5() on a non-object in E:\test.php on line 20

Line 20 is the var_dump(); line

I don't understand why use $clientSOAP->MD5 is a problem What is the correct solution ? Thanks in advance

Ps:excuse me if I speak very well English, this isn't my language

Upvotes: 0

Views: 158

Answers (1)

Mika&#235;l DELSOL
Mika&#235;l DELSOL

Reputation: 760

The right code for number 2 is :

public function get_fonction()
{
    $sestruct = new stdClass();
    $sestruct->value = "test";
    var_dump($this->clientSOAP->MD5($sestruct));
}

because the $clientSOAP variable is not defined as in the code n° 1

Upvotes: 1

Related Questions