In effetti non mi sono spiegato bene, ma sono riuscito nell'intendo, ho snellito la classe realizzata, per farti vedere il codice:
Codice PHP:
<?php
class tmpelement{
private $dato;
function __construct($value='') {
if(is_string($value) || is_numeric($value)){
$this->dato=$value;
}
}
function __set($name, $value) {
if(isset($this->$name) && $this->$name instanceof tmpelement)
return $this->$name;
if(property_exists('tmpelement',$name))
return;
$this->$name=new tmpelement($value);
return $this->$name;
}
function __get($name) {
if(isset($this->$name) && $this->$name instanceof tmpelement)
return $this->$name;
if(property_exists('tmpelement',$name))
return;
$this->$name=new tmpelement();
return $this->$name;
}
function __toString() {
if(is_numeric($this->dato))
return (string)$this->dato;
return ($this->dato) ? $this->dato : '';
}
}
class tmp_header{
private $dato;
function __construct($value='') {
if(is_string($value) || is_numeric($value)){
$this->dato=$value;
}
}
function __set($name, $value) {
if(isset($this->$name) && $this->$name instanceof tmpelement)
return $this->$name;
if(property_exists('tmp_header',$name))
return;
$this->$name=new tmpelement($value);
return $this->$name;
}
function __get($name) {
if(isset($this->$name) && $this->$name instanceof tmpelement)
return $this->$name;
if(property_exists('tmp_header',$name))
return;
$this->$name=new tmpelement();
return $this->$name;
}
function __toString() {
if(is_numeric($this->dato))
return (string)$this->dato;
return ($this->dato) ? $this->dato : '';
}
}
class tmp_master{
public $Header;
}
$xml=new tmp_master();
$header=$xml->Header=new tmp_header();
$header->Obj1->Obj2->str1='PIPPO';
$header->Obj1->str1='PLUTO';
$header->Obj1->Obj2->str2='PAPERINO';
echo '<pre>';
echo $header->Obj1->Obj2->str1.'<br>';
echo $header->Obj1->str1.'<br>';
echo $header->Obj1->Obj2->str2.'<br>';
var_dump($xml);