Преглед на файлове

prevent method call on null

mattw преди 12 години
родител
ревизия
8f2e2c4825
променени са 1 файла, в които са добавени 5 реда и са изтрити 3 реда
  1. 5 3
      Serializer/XmlSerializationVisitor.php

+ 5 - 3
Serializer/XmlSerializationVisitor.php

@@ -72,16 +72,18 @@ class XmlSerializationVisitor extends AbstractVisitor
 
     public function visitNull($data, array $type)
     {
-        $node = $this->document->createAttribute('xsi:nil');
-        $node->value = 'true';
-
         if (null === $this->document) {
             $this->document = $this->createDocument(null, null, true);
+            $node = $this->document->createAttribute('xsi:nil');
+            $node->value = 'true';
             $this->currentNode->appendChild($this->document->appendChild($node));
 
             return;
         }
 
+        $node = $this->document->createAttribute('xsi:nil');
+        $node->value = 'true';
+
         return $node;
     }