Доброе время суток Ктонить работал с https://github.com/goetas-webservices/xsd2php ? с помошью этой штуки я создал класс .. ок это получилось PHP: class RequestType { /** * @property string $oKATO */ private $oKATO = null; public function getOKATO() { return $this->oKATO; } /** * Sets a new oKATO * * @param string $oKATO * @return self */ public function setOKATO($oKATO) { $this->oKATO = $oKATO; return $this; } } ок.. работаем - забиваем .. получаем - все прекрасно .. кстати - он сделал еше 1 класс PHP: /** * Class representing Request */ class Request extends RequestType { } через который и происходит вся работа далее мне надо создать xml я долго мучился .. и вот что собрал PHP: class XmlDomConstruct extends DOMDocument { /** * Constructs elements and texts from an array or string. * The array can contain an element's name in the index part * and an element's text in the value part. * * It can also creates an xml with the same element tagName on the same * level. * * ex: * <nodes> * <node>text</node> * <node> * <field>hello</field> * <field>world</field> * </node> * </nodes> * * Array should then look like: * * Array ( * "nodes" => Array ( * "node" => Array ( * 0 => "text" * 1 => Array ( * "field" => Array ( * 0 => "hello" * 1 => "world" * ) * ) * ) * ) * ) * * @param mixed $mixed An array or string. * * @param DOMElement[optional] $domElement Then element * from where the array will be construct to. * */ public function fromMixed($mixed, DOMElement $domElement = null) { $domElement = is_null($domElement) ? $this : $domElement; if (is_array($mixed)) { foreach( $mixed as $index => $mixedElement ) { if ( is_int($index) ) { if ( $index == 0 ) { $node = $domElement; } else { $node = $this->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $node = $this->createElement($index); $domElement->appendChild($node); } $this->fromMixed($mixedElement, $node); } } else { $domElement->appendChild($this->createTextNode($mixed)); } } } в класс Request добавил функцию PHP: function get_vars(){ $all = get_object_vars($this); return $all; а теперь самое интересное - как вы могли заметить в классе RequestType - все переменные private и за рамки класса они не выходят .. PHP: $dom = new XmlDomConstruct('1.0', 'utf-8'); $dom->fromMixed($test->get_vars()); echo $dom->saveXML(); кто подскажет как правильно после генерации классов генерировать xml
если я тебя правильно понял, то тебе нужно вывести все свойства, независимо от их области видимости? мне такая конструкция помогла Код (Text): class Test { public function __construct($a = 1, $b = 2, $c = 3){ $this->a = $a; $this->b = $b; $this->c = $c; } private $a; public $b; protected $c; public function v(){ return get_object_vars($this); } } class TestP extends Test{ private $d = 10; public $e = 20; protected $f = 30; public function v(){ $aParent = parent::v(); $aThis = get_object_vars($this); return array_merge($aParent, $aThis); } } $o = new TestP(); s::p($o->v()); /* s::p(); - это просто обертка над print_r() Array ( [e] => 20 [f] => 30 [a] => 1 [b] => 2 [c] => 3 [d] => 10 ) */
Пример для раскуривания: PHP: <?php class ParentTest { private $parentPrivateProperty = 'parentPrivatePropertyValue'; } class Test extends ParentTest { private $privateProperty = 'privateValue'; protected $protectedProperty = 'protectedValue'; public $publicProperty = 'publicValue'; } $object = new Test(); $object->publicProperty = 'newPublicValue'; $object->newProperty = ' netPropertyValue'; $reflection = new ReflectionObject($object); while ($reflection) { echo $reflection->getName().PHP_EOL; foreach ($reflection->getProperties() as $property) { if ($property->isProtected() || $property->isPrivate()) { $property->setAccessible(true); echo $property->getName() . '[private]: ' . $property->getValue($object) . PHP_EOL; $property->setAccessible(false); } else { echo $property->getName() . '[public]: ' . $property->getValue($object) . PHP_EOL; } } echo 'Default properties:' . PHP_EOL; foreach ($reflection->getDefaultProperties() as $name => $value) { echo $name . ': ' . $value . PHP_EOL; } $reflection = $reflection->getParentClass(); } Код (Text): Test privateProperty[private]: privateValue protectedProperty[private]: protectedValue publicProperty[public]: newPublicValue newProperty[public]: netPropertyValue Default properties: privateProperty: privateValue protectedProperty: protectedValue publicProperty: publicValue ParentTest parentPrivateProperty[private]: parentPrivatePropertyValue Default properties: parentPrivateProperty: parentPrivatePropertyValue Доки: https://php.ru/manual/book.reflection.html