PHP - print_r in xml is bringing Class name

Asked

Viewed 102 times

0

I have a class called Cliente.php connecting to the web service and have another call Requisição.php that generates the XML request and sends to the Cliente.php.

The problem is that the answer I get from the web service I can only show with print_r in class Cliente.php and I can’t show it in class Requisição.php, even putting Cliente with return.

WHAT IT SHOWS IS THE NAME IS: Object Client ( )

class Cliente {

    public function __construct($requisicao) {
        //Endereço e conexão com  o web service
        $client = new SoapClient("http://192.168.1.104:8082/wsdl/FChamada");
        //Requisição ao web service 
        $obj = $client->Requisicao($requisicao);
        //Retorno(Resposta) do web service
        $xml = simplexml_load_string($obj);
        //Retorna o a resposta do web service
        return $xml;  
    }
}



class Requisicao {

    /***********************************************************************
     ********************* REQUISÃO ****************************************
     **********************************************************************/
    public function query() {

        $req = new Requisicao_XML();
        //Gerando o xml requisição
        $requisicao = $req->toXML();

        //Envia o xml requisição para a classe Cliente e recebe o xml resposta
        $xml = new Cliente($requisicao);
        //Deveria mostrar o xml resposta
        print_r($xml)
    }

}
  • Why Return in constructor method?

  • I’ve put in another method, and the same thing happens.

  • It’s a little confusing to me what you want to do and why this class organization...

  • Hey guy was bad, the mistake was mine, I took it from the builder and it really worked. Thanks.

1 answer

0


In the method __contruct there is no return, because the return is the object. What you can do in this case is create a method.

class Cliente {

    public static function Get($requisicao) {
        //Endereço e conexão com  o web service
        $client = new SoapClient("http://192.168.1.104:8082/wsdl/FChamada");
        //Requisição ao web service 
        $obj = $client->Requisicao($requisicao);
        //Retorno(Resposta) do web service
        $xml = simplexml_load_string($obj);
        //Retorna o a resposta do web service
        return $xml;  
    }
}



class Requisicao {

    /***********************************************************************
     ********************* REQUISÃO ****************************************
     **********************************************************************/
    public function query() {

        $req = new Requisicao_XML();
        //Gerando o xml requisição
        $requisicao = $req->toXML();

        //Envia o xml requisição para a classe Cliente e recebe o xml resposta
        $xml = Cliente::Get($requisicao);
        //Mostrar o xml resposta
        print_r($xml)
    }

}
  • Thank you. That’s what I did and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.