João Mantovani João Mantovani - 14 days ago 8
PHP Question

Can't recover variable in my PHP class

Here is the class

class cwb extends SoapClient {
protected $raw_xml;
protected $filename;
public $users;

/**
* @param mixed $entity
*/
public function __construct($entity = '') {
parent::__construct('http://privatesite?WSDL');
$this->raw_xml = $this->createXmlFile($entity->token);
$this->filename = $this->createXmlFilename($entity->nome);
$this->users = $this->createUserArray();
}

/**
* @return string
*/
private function getFullPath(){
return (string)$this->getPath() . '/' . $this->filename;
}
}


When I try to access my
protected $filename
in
private function getFullPath()
, my variable is always empty, anyone knows a solution to access the content of the variable?

Answer

Changed the load order from:

$this->raw_xml  = $this->createXmlFile($entity->token);
$this->filename = $this->createXmlFilename($entity->nome);
$this->users    = $this->createUserArray();

To:

$this->users    = $this->createUserArray();
$this->raw_xml  = $this->createXmlFile($entity->token);
$this->filename = $this->createXmlFilename($entity->nome);

Loaded the necessary elements to recover the variable in the next requisition.

Thanks to @Dave Chen to the answer.