Browse Source

Checking if object before calling method on it

Guillaume "Elektordi" Genty 9 years ago
parent
commit
b5cc45ceda
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/Utility/Xml.php

+ 3 - 3
src/Utility/Xml.php

@@ -203,7 +203,7 @@ class Xml
      */
     public static function fromArray($input, $options = [])
     {
-        if (method_exists($input, 'toArray')) {
+        if (is_object($input) && method_exists($input, 'toArray')) {
             $input = $input->toArray();
         }
         if (!is_array($input) || count($input) !== 1) {
@@ -257,7 +257,7 @@ class Xml
         }
         foreach ($data as $key => $value) {
             if (is_string($key)) {
-                if (method_exists($value, 'toArray')) {
+                if (is_object($value) && method_exists($value, 'toArray')) {
                     $value = $value->toArray();
                 }
 
@@ -323,7 +323,7 @@ class Xml
     {
         extract($data);
         $childNS = $childValue = null;
-        if (method_exists($value, 'toArray')) {
+        if (is_object($value) && method_exists($value, 'toArray')) {
             $value = $value->toArray();
         }
         if (is_array($value)) {