diff --git a/lib/PhpParser/Unserializer/XML.php b/lib/PhpParser/Unserializer/XML.php index b3bf56f..79b4658 100644 --- a/lib/PhpParser/Unserializer/XML.php +++ b/lib/PhpParser/Unserializer/XML.php @@ -49,9 +49,8 @@ class XML implements Unserializer } } - protected function readNode() - { - $className = 'PHPParser_Node_' . $this->reader->localName; + protected function readNode() { + $className = $this->getClassNameFromType($this->reader->localName); // create the node without calling it's constructor $node = unserialize( @@ -136,4 +135,12 @@ class XML implements Unserializer $this->reader->getAttribute('line') ); } + + protected function getClassNameFromType($type) { + $className = 'PhpParser\\Node\\' . strtr($type, '_', '\\'); + if (!class_exists($className)) { + $className .= '_'; + } + return $className; + } } diff --git a/test/PhpParser/Unserializer/XMLTest.php b/test/PhpParser/Unserializer/XMLTest.php index d23a120..52b082d 100644 --- a/test/PhpParser/Unserializer/XMLTest.php +++ b/test/PhpParser/Unserializer/XMLTest.php @@ -46,7 +46,7 @@ XML; $xml = << - + XML;