]> git.sesse.net Git - xml-template/commitdiff
Revert the NULL mess in PHP; we don't need it anyhow.
authorsgunderson@bigfoot.com <>
Sat, 12 Aug 2006 22:35:28 +0000 (00:35 +0200)
committersgunderson@bigfoot.com <>
Sat, 12 Aug 2006 22:35:28 +0000 (00:35 +0200)
php/xml-template.php

index f450e1bf5b22f4f5673eb87be1419066254b3931..1a7434ae99947db0d62c56f411ea10cdd8f30484 100644 (file)
@@ -21,14 +21,14 @@ function XML_Template_process($node, $obj, $clean = 1)
                $newobj = own_clone_node($obj, $node->owner_document());
                $node->append_child($newobj);
 
-               XML_Template_process($newobj, NULL, $clean);
-       } else if (isset($obj) && !is_array($obj)) {               # overwrite
+               XML_Template_process($newobj, array(), $clean);
+       } else if (!is_array($obj)) {                         # overwrite
                foreach ($node->child_nodes() as $child) {
                        $node->remove_child($child);
                }
                $doc = $node->owner_document();
                $node->add_child($doc->create_text_node($obj));
-       } else if (!isset($obj) || is_associative_array($obj)) {   # substitute
+       } else if (is_associative_array($obj)) {              # substitute
                foreach ($node->child_nodes() as $child) {
                        $processed = false;
 
@@ -49,21 +49,19 @@ function XML_Template_process($node, $obj, $clean = 1)
                        
                                # check all substitutions to see if we found anything
                                # appropriate
-                               if (isset($obj)) {
-                                       foreach (array_keys($obj) as $key) {
-                                               # FIXME: we would want something like \Q and \E here...
-                                               if (preg_match('/^' . $tag . '\/(.*)$/', $key, $matches) ||
-                                                   (isset($id) && preg_match('/^#' . $id . '\/(.*)$/', $key, $matches))) {
-                                                       $child->set_attribute($matches[1], $obj[$key]);
-                                               }
+                               foreach (array_keys($obj) as $key) {
+                                       # FIXME: we would want something like \Q and \E here...
+                                       if (preg_match('/^' . $tag . '\/(.*)$/', $key, $matches) ||
+                                           (isset($id) && preg_match('/^#' . $id . '\/(.*)$/', $key, $matches))) {
+                                               $child->set_attribute($matches[1], $obj[$key]);
+                                       }
 
-                                               if ($processed) {
-                                                       continue;
-                                               }
-                                               if ($key == $tag || (isset($id) && $key == ('#'.$id))) {
-                                                       XML_Template_process($child, $obj[$key], $clean);
-                                                       $processed = true;
-                                               }
+                                       if ($processed) {
+                                               continue;
+                                       }
+                                       if ($key == $tag || (isset($id) && $key == ('#'.$id))) {
+                                               XML_Template_process($child, $obj[$key], $clean);
+                                               $processed = true;
                                        }
                                }
                        }
@@ -179,11 +177,6 @@ function is_associative_array($arr)
        if (!is_array($arr)) {
                return false;
        }
-
-       if (count($arr) == 0) {
-               return false;       // special case
-       }
-
        $diff = array_diff(range(0, count($arr) - 1), array_keys($arr));
        return (count($diff) > 0);
 }