]> granicus.if.org Git - php/commitdiff
- Change var_dump to include all that is reachable, incl. @attributes
authorMarcus Boerger <helly@php.net>
Sat, 29 Oct 2005 16:12:57 +0000 (16:12 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 29 Oct 2005 16:12:57 +0000 (16:12 +0000)
- Adapt tests and add new one

25 files changed:
ext/simplexml/simplexml.c
ext/simplexml/tests/000.phpt [new file with mode: 0755]
ext/simplexml/tests/000.xml [new file with mode: 0755]
ext/simplexml/tests/001.phpt
ext/simplexml/tests/002.phpt
ext/simplexml/tests/003.phpt
ext/simplexml/tests/004.phpt
ext/simplexml/tests/005.phpt
ext/simplexml/tests/006.phpt
ext/simplexml/tests/007.phpt
ext/simplexml/tests/008.phpt
ext/simplexml/tests/009.phpt
ext/simplexml/tests/010.phpt
ext/simplexml/tests/011.phpt
ext/simplexml/tests/012.phpt
ext/simplexml/tests/013.phpt
ext/simplexml/tests/019.phpt
ext/simplexml/tests/020.phpt
ext/simplexml/tests/021.phpt
ext/simplexml/tests/022.phpt
ext/simplexml/tests/023.phpt
ext/simplexml/tests/bug27010.phpt
ext/simplexml/tests/profile11.phpt
ext/simplexml/tests/simplexml_import_dom.phpt
ext/simplexml/tests/sxe.dtd

index 980c33da50f5a70c27d590559250061a1eb96a58..9d73df2ebb79a2c753cd97390eee095d023e7118 100644 (file)
@@ -38,6 +38,8 @@
 #include "ext/spl/spl_sxe.h"
 #endif
 
+#define SXE_ELEMENT_BY_NAME 0
+
 zend_class_entry *sxe_class_entry = NULL;
 
 ZEND_API zend_class_entry *sxe_get_element_class_entry(TSRMLS_D)
@@ -112,10 +114,7 @@ static xmlNodePtr php_sxe_get_first_node(php_sxe_object *sxe, xmlNodePtr node TS
        }
 }
 
-/* {{{ match_ns()
- */
-static inline int
-match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name)
+static inline int match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name) /* {{{ */
 {
        if (name == NULL && (node->ns == NULL || node->ns->prefix == NULL)) {
                return 1;
@@ -129,9 +128,8 @@ match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name)
 }
 /* }}} */
 
-/* {{{ sxe_get_element_node()
- */
-static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xmlNodePtr node) {
+static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xmlNodePtr node) /* {{{ */
+{
        long nodendx = 0;
 
        if (sxe->iter.type == SXE_ITER_NONE) {
@@ -156,6 +154,71 @@ next_iter:
 }
 /* }}} */
 
+#if SXE_ELEMENT_BY_NAME
+static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char *name TSRMLS_DC) /* {{{ */
+{
+       while (node) {
+               SKIP_TEXT(node)
+               if (node->type == XML_ELEMENT_NODE && match_ns(sxe, node, sxe->iter.nsprefix)) {
+                       if (!xmlStrcmp(node->name, name)) {
+                               return node;
+                       }
+               }
+next_iter:
+               node = node->next;
+       }
+       return NULL;
+} /* }}} */
+
+static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char **name, int *type TSRMLS_DC) /* {{{ */
+{
+       int         orgtype;
+       xmlNodePtr  orgnode = node;
+       xmlNodePtr  retnode = NULL;
+
+       if (sxe->iter.type != SXE_ITER_ATTRLIST)
+       {
+               orgtype = sxe->iter.type;
+               if (sxe->iter.type == SXE_ITER_NONE) {
+                       sxe->iter.type = SXE_ITER_CHILD;
+               }
+               node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+               sxe->iter.type = orgtype;
+       }
+
+       if (sxe->iter.type == SXE_ITER_ELEMENT) {
+               orgnode = sxe_find_element_by_name(sxe, node, sxe->iter.name TSRMLS_CC);
+               node = orgnode->children;
+       }
+
+       while (node) {
+               SKIP_TEXT(node)
+               if (node->type == XML_ELEMENT_NODE && match_ns(sxe, node, sxe->iter.nsprefix)) {
+                       if (!xmlStrcmp(node->name, *name)) {
+                               if (1||retnode)
+                               {
+                                       *type = SXE_ITER_ELEMENT;
+                                       return orgnode;
+                               }
+                               retnode = node;
+                       }
+               }
+next_iter:
+               node = node->next;
+       }
+
+       if (retnode)
+       {
+               *type = SXE_ITER_NONE;
+               *name = NULL;
+               return retnode;
+       }
+
+       return NULL;
+}
+/* }}} */
+#endif /* SXE_ELEMENT_BY_NAME */
+
 /* {{{ sxe_prop_dim_read()
  */
 static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, zend_bool attribs, zend_bool silent TSRMLS_DC)
@@ -166,7 +229,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
        xmlNodePtr      node;
        xmlAttrPtr      attr;
        zval            tmp_zv;
-       int                             nodendx = 0;
+       int             nodendx = 0;
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
 
@@ -175,6 +238,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                        attribs = 0;
                        elements = 1;
                }
+               name = NULL;
        } else {
                if (Z_TYPE_P(member) != IS_STRING) {
                        tmp_zv = *member;
@@ -182,24 +246,23 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                        member = &tmp_zv;
                        convert_to_string(member);
                }
+               name = Z_STRVAL_P(member);
        }
 
        MAKE_STD_ZVAL(return_value);
        ZVAL_NULL(return_value);
 
-       name = Z_STRVAL_P(member);
-
        GET_NODE(sxe, node);
 
-       if (sxe->iter.type != SXE_ITER_CHILD && sxe->iter.type != SXE_ITER_ATTRLIST) {
+       if (sxe->iter.type == SXE_ITER_ATTRLIST) {
+               attribs = 1;
+               elements = 0;           
+       } else if (sxe->iter.type != SXE_ITER_CHILD && sxe->iter.type != SXE_ITER_ATTRLIST) {
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
        }
-
        if (node) {
                if (attribs) {
-                       if (Z_TYPE_P(member) == IS_LONG && sxe->iter.type != SXE_ITER_ATTRLIST) {
-                               attr = NULL;
-                       } else {
+                       if (Z_TYPE_P(member) != IS_LONG || sxe->iter.type == SXE_ITER_ATTRLIST) {
                                attr = node->properties;
                                if (Z_TYPE_P(member) == IS_LONG) {
                                        while (attr && nodendx <= Z_LVAL_P(member)) {
@@ -237,7 +300,17 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                                        _node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix TSRMLS_CC);
                                }
                        } else {
+#if SXE_ELEMENT_BY_NAME
+                               int newtype;
+
+                               GET_NODE(sxe, node);
+                               node = sxe_get_element_by_name(sxe, node, &name, &newtype TSRMLS_CC);
+                               if (node) {
+                                       _node_as_zval(sxe, node, return_value, newtype, name, sxe->iter.nsprefix TSRMLS_CC);
+                               }
+#else
                                _node_as_zval(sxe, node, return_value, SXE_ITER_ELEMENT, name, sxe->iter.nsprefix TSRMLS_CC);
+#endif
                        }
                }
        }
@@ -671,19 +744,41 @@ _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval **value, cha
 }
 /* }}} */
 
+static void sxe_properties_add(HashTable *rv, char *name, int namelen, zval *value TSRMLS_DC)
+{
+       zval  **data_ptr;
+       zval  *newptr;
+       ulong h = zend_hash_func(name, namelen);
+
+       if (zend_hash_quick_find(rv, name, namelen, h, (void **) &data_ptr) == SUCCESS) {
+               if (Z_TYPE_PP(data_ptr) == IS_ARRAY) {
+                       zend_hash_next_index_insert(Z_ARRVAL_PP(data_ptr), &value, sizeof(zval *), NULL);
+               } else {
+                       MAKE_STD_ZVAL(newptr);
+                       array_init(newptr);
+
+                       zval_add_ref(data_ptr);
+                       zend_hash_next_index_insert(Z_ARRVAL_P(newptr), data_ptr, sizeof(zval *), NULL);
+                       zend_hash_next_index_insert(Z_ARRVAL_P(newptr), &value, sizeof(zval *), NULL);
+
+                       zend_hash_quick_update(rv, name, namelen, h, &newptr, sizeof(zval *), NULL);
+               }
+       } else {
+               zend_hash_quick_update(rv, name, namelen, h, &value, sizeof(zval *), NULL);
+       }
+}
+
 /* {{{ sxe_properties_get()
  */
-static HashTable *
-sxe_properties_get(zval *object TSRMLS_DC)
+static HashTable * sxe_properties_get(zval *object TSRMLS_DC)
 {
-       zval           **data_ptr;
        zval            *value;
-       zval            *newptr;
+       zval            *zattr;
        HashTable       *rv;
        php_sxe_object  *sxe;
        char            *name;
        xmlNodePtr       node;
-       ulong            h;
+       xmlAttrPtr       attr;
        int              namelen;
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
@@ -698,9 +793,31 @@ sxe_properties_get(zval *object TSRMLS_DC)
        }
 
        GET_NODE(sxe, node);
-       node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+       if (1||sxe->iter.type != SXE_ITER_CHILD) {
+               if (sxe->iter.type == SXE_ITER_ELEMENT) {
+                       node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+               }
+               attr = node ? (xmlAttrPtr)node->properties : NULL;
+               zattr = NULL;
+               while (attr) {
+                       if (match_ns(sxe, (xmlNodePtr)attr, sxe->iter.nsprefix)) {
+                               MAKE_STD_ZVAL(value);
+                               ZVAL_STRING(value, xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, attr->children, 1), 1);
+                               namelen = xmlStrlen(attr->name) + 1;
+                               if (!zattr) {
+                                       MAKE_STD_ZVAL(zattr);
+                                       array_init(zattr);
+                                       sxe_properties_add(rv, "@attributes", sizeof("@attributes"), zattr TSRMLS_CC);
+                               }
+                               add_assoc_zval_ex(zattr, (char*)attr->name, namelen, value);
+                       }
+                       attr = attr->next;
+               }
+       }
 
-       if (node) {
+       GET_NODE(sxe, node);
+       node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+       if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
                if (node->type == XML_ATTRIBUTE_NODE) {
                        MAKE_STD_ZVAL(value);
                        ZVAL_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), value, xmlNodeListGetString(node->doc, node->children, 1), 1);
@@ -735,24 +852,7 @@ sxe_properties_get(zval *object TSRMLS_DC)
 
                        _get_base_node_value(sxe, node, &value, sxe->iter.nsprefix TSRMLS_CC);
 
-                       h = zend_hash_func(name, namelen);
-                       if (zend_hash_quick_find(rv, name, namelen, h, (void **) &data_ptr) == SUCCESS) {
-                               if (Z_TYPE_PP(data_ptr) == IS_ARRAY) {
-                                       zend_hash_next_index_insert(Z_ARRVAL_PP(data_ptr), &value, sizeof(zval *), NULL);
-                               } else {
-                                       MAKE_STD_ZVAL(newptr);
-                                       array_init(newptr);
-
-                                       zval_add_ref(data_ptr);
-                                       zend_hash_next_index_insert(Z_ARRVAL_P(newptr), data_ptr, sizeof(zval *), NULL);
-                                       zend_hash_next_index_insert(Z_ARRVAL_P(newptr), &value, sizeof(zval *), NULL);
-
-                                       zend_hash_quick_update(rv, name, namelen, h, &newptr, sizeof(zval *), NULL);
-                               }
-                       } else {
-                               zend_hash_quick_update(rv, name, namelen, h, &value, sizeof(zval *), NULL);
-                       }
-
+                       sxe_properties_add(rv, name, namelen, value TSRMLS_CC);
 next_iter:
                        node = node->next;
                }
@@ -1007,8 +1107,7 @@ SXE_METHOD(attributes)
 
 /* {{{ cast_object()
  */
-static int
-cast_object(zval *object, int type, char *contents TSRMLS_DC)
+static int cast_object(zval *object, int type, char *contents TSRMLS_DC)
 {
        if (contents) {
                ZVAL_STRINGL(object, contents, strlen(contents), 1);
@@ -1046,8 +1145,7 @@ cast_object(zval *object, int type, char *contents TSRMLS_DC)
 
 /* {{{ sxe_object_cast()
  */
-static int
-sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
+static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
 {
        php_sxe_object *sxe;
        char           *contents = NULL;
diff --git a/ext/simplexml/tests/000.phpt b/ext/simplexml/tests/000.phpt
new file mode 100755 (executable)
index 0000000..0499bcd
--- /dev/null
@@ -0,0 +1,220 @@
+--TEST--
+SimpleXML: var_dump()
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip"; ?>
+--FILE--
+<?php 
+
+$sxe = simplexml_load_file(dirname(__FILE__).'/000.xml');
+
+function test($what)
+{
+       global $sxe;
+       echo "===$what\n";
+       eval("var_dump(isset(\$$what));");
+       eval("var_dump(\$$what);");
+}
+
+test('sxe');
+test('sxe->elem1');
+test('sxe->elem1[0]');
+test('sxe->elem1[0]->elem2');
+test('sxe->elem1[0]->elem2->bla');
+test('sxe->elem1[0]["attr1"]');
+test('sxe->elem1[0]->attr1');
+test('sxe->elem1[1]');
+test('sxe->elem1[2]');
+test('sxe->elem11');
+test('sxe->elem11->elem111');
+test('sxe->elem11->elem111->elem1111');
+test('sxe->elem22');
+test('sxe->elem22->elem222');
+test('sxe->elem22->attr22');
+test('sxe->elem22["attr22"]');
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+===sxe
+bool(true)
+object(SimpleXMLElement)#%d (3) {
+  ["@attributes"]=>
+  array(1) {
+    ["id"]=>
+    string(3) "123"
+  }
+  ["elem1"]=>
+  array(2) {
+    [0]=>
+    string(36) "There is some text.Here is some more"
+    [1]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["@attributes"]=>
+      array(2) {
+        ["attr1"]=>
+        string(2) "11"
+        ["attr2"]=>
+        string(2) "12"
+      }
+    }
+  }
+  ["elem11"]=>
+  object(SimpleXMLElement)#%d (1) {
+    ["elem111"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem1111"]=>
+      object(SimpleXMLElement)#%d (0) {
+      }
+    }
+  }
+}
+===sxe->elem1
+bool(true)
+object(SimpleXMLElement)#%d (3) {
+  ["@attributes"]=>
+  array(2) {
+    ["attr1"]=>
+    string(5) "first"
+    ["attr2"]=>
+    string(6) "second"
+  }
+  ["comment"]=>
+  object(SimpleXMLElement)#%d (0) {
+  }
+  ["elem2"]=>
+  object(SimpleXMLElement)#%d (2) {
+    ["@attributes"]=>
+    array(2) {
+      ["att25"]=>
+      string(2) "25"
+      ["att42"]=>
+      string(2) "42"
+    }
+    ["elem3"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem4"]=>
+      object(SimpleXMLElement)#%d (1) {
+        ["test"]=>
+        object(SimpleXMLElement)#%d (0) {
+        }
+      }
+    }
+  }
+}
+===sxe->elem1[0]
+bool(true)
+object(SimpleXMLElement)#%d (3) {
+  ["@attributes"]=>
+  array(2) {
+    ["attr1"]=>
+    string(5) "first"
+    ["attr2"]=>
+    string(6) "second"
+  }
+  ["comment"]=>
+  object(SimpleXMLElement)#%d (0) {
+  }
+  ["elem2"]=>
+  object(SimpleXMLElement)#%d (2) {
+    ["@attributes"]=>
+    array(2) {
+      ["att25"]=>
+      string(2) "25"
+      ["att42"]=>
+      string(2) "42"
+    }
+    ["elem3"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem4"]=>
+      object(SimpleXMLElement)#%d (1) {
+        ["test"]=>
+        object(SimpleXMLElement)#%d (0) {
+        }
+      }
+    }
+  }
+}
+===sxe->elem1[0]->elem2
+bool(true)
+object(SimpleXMLElement)#%d (2) {
+  ["@attributes"]=>
+  array(2) {
+    ["att25"]=>
+    string(2) "25"
+    ["att42"]=>
+    string(2) "42"
+  }
+  ["elem3"]=>
+  object(SimpleXMLElement)#%d (1) {
+    ["elem4"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["test"]=>
+      object(SimpleXMLElement)#%d (0) {
+      }
+    }
+  }
+}
+===sxe->elem1[0]->elem2->bla
+bool(false)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem1[0]["attr1"]
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+  [0]=>
+  string(5) "first"
+}
+===sxe->elem1[0]->attr1
+bool(false)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem1[1]
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+  ["@attributes"]=>
+  array(2) {
+    ["attr1"]=>
+    string(2) "11"
+    ["attr2"]=>
+    string(2) "12"
+  }
+}
+===sxe->elem1[2]
+bool(false)
+NULL
+===sxe->elem11
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+  ["elem111"]=>
+  object(SimpleXMLElement)#%d (1) {
+    ["elem1111"]=>
+    object(SimpleXMLElement)#%d (0) {
+    }
+  }
+}
+===sxe->elem11->elem111
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+  ["elem1111"]=>
+  object(SimpleXMLElement)#%d (0) {
+  }
+}
+===sxe->elem11->elem111->elem1111
+bool(true)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem22
+bool(false)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem22->elem222
+bool(false)
+NULL
+===sxe->elem22->attr22
+bool(false)
+NULL
+===sxe->elem22["attr22"]
+bool(false)
+NULL
+===DONE===
diff --git a/ext/simplexml/tests/000.xml b/ext/simplexml/tests/000.xml
new file mode 100755 (executable)
index 0000000..b0f2785
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version='1.0'?>
+<!DOCTYPE sxe SYSTEM "sxe.dtd" [
+<!ENTITY % incent SYSTEM "sxe.ent">
+%incent;
+]>
+<sxe id="123">
+ <elem1 attr1='first' attr2='second'>There is some text.<!-- comment --><elem2 att25='25' att42='42'>
+   <elem3>
+    <elem4>
+     <?test processing instruction ?>
+    </elem4>
+   </elem3>
+  </elem2>Here is some more</elem1>
+ <elem1 attr1='11' attr2='12'/>
+ <elem11><elem111><elem1111/></elem111></elem11>
+</sxe>
\ No newline at end of file
index cacc2d30663793924e70d9c223917fbdf3102644..0be77710e5fbb3a9c3ba097c69e194cb5f697bd9 100644 (file)
@@ -5,39 +5,39 @@ SimpleXML: Simple document
 --FILE--
 <?php 
 
-$sxe = simplexml_load_file(dirname(__FILE__).'/sxe.xml');
-
-print_r($sxe);
-
-echo "---Done---\n";
+var_dump(simplexml_load_file(dirname(__FILE__).'/sxe.xml'));
 
 ?>
---EXPECT--
-SimpleXMLElement Object
-(
-    [elem1] => SimpleXMLElement Object
-        (
-            [comment] => SimpleXMLElement Object
-                (
-                )
-
-            [elem2] => SimpleXMLElement Object
-                (
-                    [elem3] => SimpleXMLElement Object
-                        (
-                            [elem4] => SimpleXMLElement Object
-                                (
-                                    [test] => SimpleXMLElement Object
-                                        (
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
----Done--- 
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+  ["@attributes"]=>
+  array(1) {
+    ["id"]=>
+    string(5) "elem1"
+  }
+  ["elem1"]=>
+  object(SimpleXMLElement)#%d (3) {
+    ["@attributes"]=>
+    array(1) {
+      ["attr1"]=>
+      string(5) "first"
+    }
+    ["comment"]=>
+    object(SimpleXMLElement)#%d (0) {
+    }
+    ["elem2"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem3"]=>
+      object(SimpleXMLElement)#%d (1) {
+        ["elem4"]=>
+        object(SimpleXMLElement)#%d (1) {
+          ["test"]=>
+          object(SimpleXMLElement)#%d (0) {
+          }
+        }
+      }
+    }
+  }
+}
+===DONE===
index 95d644fe7142371950b72094209cb261c9b0e6f6..4f1f6b622406ce45c1ce55445d5558add7f88788 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and clone
+SimpleXML: clone
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
@@ -26,37 +26,39 @@ $sxe = simplexml_load_string($xml);
 
 $copy = clone $sxe;
 
-print_r($copy);
-
-echo "---Done---\n";
+var_dump($copy);
 
 ?>
---EXPECT--
-SimpleXMLElement Object
-(
-    [elem1] => SimpleXMLElement Object
-        (
-            [comment] => SimpleXMLElement Object
-                (
-                )
-
-            [elem2] => SimpleXMLElement Object
-                (
-                    [elem3] => SimpleXMLElement Object
-                        (
-                            [elem4] => SimpleXMLElement Object
-                                (
-                                    [test] => SimpleXMLElement Object
-                                        (
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
----Done--- 
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+  ["@attributes"]=>
+  array(1) {
+    ["id"]=>
+    string(5) "elem1"
+  }
+  ["elem1"]=>
+  object(SimpleXMLElement)#%d (3) {
+    ["@attributes"]=>
+    array(1) {
+      ["attr1"]=>
+      string(5) "first"
+    }
+    ["comment"]=>
+    object(SimpleXMLElement)#%d (0) {
+    }
+    ["elem2"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem3"]=>
+      object(SimpleXMLElement)#%d (1) {
+        ["elem4"]=>
+        object(SimpleXMLElement)#%d (1) {
+          ["test"]=>
+          object(SimpleXMLElement)#%d (0) {
+          }
+        }
+      }
+    }
+  }
+}
+===DONE===
index 96aad372dac0d9e51701d2fa5b1dbee9e008464f..105f616d60e52300d872c0dd1ed61b112d31f654 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and Entities
+SimpleXML: Entities
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
@@ -26,44 +26,44 @@ $xml =<<<EOF
 </sxe>
 EOF;
 
-$sxe = simplexml_load_string($xml);
-
-print_r($sxe);
-
-echo "---Done---\n";
+var_dump(simplexml_load_string($xml));
 
 ?>
---EXPECT--
-SimpleXMLElement Object
-(
-    [elem1] => SimpleXMLElement Object
-        (
-            [comment] => SimpleXMLElement Object
-                (
-                )
-
-            [elem2] => SimpleXMLElement Object
-                (
-                    [elem3] => SimpleXMLElement Object
-                        (
-                            [included-entity] => SimpleXMLElement Object
-                                (
-                                    [included-entity] => This is text included from an entity
-                                )
-
-                            [elem4] => SimpleXMLElement Object
-                                (
-                                    [test] => SimpleXMLElement Object
-                                        (
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
----Done--- 
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+  ["@attributes"]=>
+  array(1) {
+    ["id"]=>
+    string(5) "elem1"
+  }
+  ["elem1"]=>
+  object(SimpleXMLElement)#%d (3) {
+    ["@attributes"]=>
+    array(1) {
+      ["attr1"]=>
+      string(5) "first"
+    }
+    ["comment"]=>
+    object(SimpleXMLElement)#%d (0) {
+    }
+    ["elem2"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem3"]=>
+      object(SimpleXMLElement)#%d (2) {
+        ["included-entity"]=>
+        object(SimpleXMLElement)#%d (1) {
+          ["included-entity"]=>
+          string(36) "This is text included from an entity"
+        }
+        ["elem4"]=>
+        object(SimpleXMLElement)#%d (1) {
+          ["test"]=>
+          object(SimpleXMLElement)#%d (0) {
+          }
+        }
+      }
+    }
+  }
+}
+===DONE===
index 82a0d68980c9d18735bd9e7b5f33f80c41ef36ba..21cb5469e01066c013ccb06f9c9e4199881dd1cb 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and CDATA
+SimpleXML: CDATA
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
@@ -25,7 +25,7 @@ $sxe = simplexml_load_string(<<<EOF
 EOF
 );
 
-print_r($sxe);
+var_dump($sxe);
 
 $elem1 = $sxe->elem1;
 $elem2 = $elem1->elem2;
@@ -33,63 +33,36 @@ var_dump(trim((string)$elem2));
 
 ?>
 ===DONE===
---EXPECT--
-SimpleXMLElement Object
-(
-    [elem1] => SimpleXMLElement Object
-        (
-            [comment] => SimpleXMLElement Object
-                (
-                )
-
-            [elem2] => SimpleXMLElement Object
-                (
-                    [elem3] => SimpleXMLElement Object
-                        (
-                            [elem4] => SimpleXMLElement Object
-                                (
-                                    [test] => SimpleXMLElement Object
-                                        (
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+  ["@attributes"]=>
+  array(1) {
+    ["id"]=>
+    string(5) "elem1"
+  }
+  ["elem1"]=>
+  object(SimpleXMLElement)#%d (3) {
+    ["@attributes"]=>
+    array(1) {
+      ["attr1"]=>
+      string(5) "first"
+    }
+    ["comment"]=>
+    object(SimpleXMLElement)#%d (0) {
+    }
+    ["elem2"]=>
+    object(SimpleXMLElement)#%d (1) {
+      ["elem3"]=>
+      object(SimpleXMLElement)#%d (1) {
+        ["elem4"]=>
+        object(SimpleXMLElement)#%d (1) {
+          ["test"]=>
+          object(SimpleXMLElement)#%d (0) {
+          }
+        }
+      }
+    }
+  }
+}
 string(11) "CDATA block"
 ===DONE===
---UEXPECT--
-SimpleXMLElement Object
-(
-    [elem1] => SimpleXMLElement Object
-        (
-            [comment] => SimpleXMLElement Object
-                (
-                )
-
-            [elem2] => SimpleXMLElement Object
-                (
-                    [elem3] => SimpleXMLElement Object
-                        (
-                            [elem4] => SimpleXMLElement Object
-                                (
-                                    [test] => SimpleXMLElement Object
-                                        (
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
-unicode(11) "CDATA block"
-===DONE===
index a2c3756f3e9c199b8f8fc89e18cdfddeee8e20b2..fc24b903aca19b5c0699e0d076d932d5ccf1d64f 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and text data
+SimpleXML: Text data
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
index 5b44c18a3113142104a3720bd817c6fc28702a3f..954452ab8e8fbb952730274ee57f906108197bc2 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and foreach
+SimpleXML: foreach
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
index 754ecf6f55879056084f726f3097e418a870f516..51d7a847f7e58031b1ec3dfde692c64fd704bd04 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and attributes
+SimpleXML: Attributes
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
@@ -48,7 +48,12 @@ var_dump($a);
 ===Done===
 --EXPECTF--
 ===Property===
-object(SimpleXMLElement)#%d (2) {
+object(SimpleXMLElement)#%d (3) {
+  ["@attributes"]=>
+  array(1) {
+    ["attr1"]=>
+    string(5) "first"
+  }
   ["comment"]=>
   object(SimpleXMLElement)#%d (0) {
   }
@@ -90,47 +95,3 @@ NULL
 int(4)
 int(4)
 ===Done===
---UEXPECTF--
-===Property===
-object(SimpleXMLElement)#%d (2) {
-  [u"comment"]=>
-  object(SimpleXMLElement)#%d (0) {
-  }
-  [u"elem2"]=>
-  object(SimpleXMLElement)#%d (1) {
-    [u"elem3"]=>
-    object(SimpleXMLElement)#%d (1) {
-      [u"elem4"]=>
-      object(SimpleXMLElement)#%d (1) {
-        [u"test"]=>
-        object(SimpleXMLElement)#%d (0) {
-        }
-      }
-    }
-  }
-}
-===Array===
-object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  unicode(5) "elem1"
-}
-object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  unicode(5) "first"
-}
-===Set===
-object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  unicode(8) "Changed1"
-}
-object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  unicode(2) "12"
-}
-===Unset===
-NULL
-NULL
-===Misc.===
-int(4)
-int(4)
-===Done===
index 76b6ec8fe8d8c1d4f7e1da5c1444b754620e7e9c..aaa2759acab3626c9b3b3c0abf8448ba09db948c 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and XPath 
+SimpleXML: XPath 
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
index 83f4629ce4883b4c82ad91568404b394c121a9f6..7663f6a92b1980dc9ed89bb981a2fb1f9e09b084 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and foreach 
+SimpleXML: foreach 
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
index ea6c7fd079194d2c53f21ecfbe65ef0184a92f8d..267780905b8c89e32250cf24a0edf25c11ef8a25 100644 (file)
@@ -26,38 +26,39 @@ $xml =<<<EOF
 </sxe>
 EOF;
 
-$sxe = simplexml_load_string($xml, 'simplexml_inherited');
-
-print_r($sxe);
+var_dump(simplexml_load_string($xml, 'simplexml_inherited'));
 
 ?>
 ===DONE===
---EXPECT--
-simplexml_inherited Object
-(
-    [elem1] => simplexml_inherited Object
-        (
-            [comment] => simplexml_inherited Object
-                (
-                )
-
-            [elem2] => simplexml_inherited Object
-                (
-                    [elem3] => simplexml_inherited Object
-                        (
-                            [elem4] => simplexml_inherited Object
-                                (
-                                    [test] => simplexml_inherited Object
-                                        (
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
+--EXPECTF--
+object(simplexml_inherited)#%d (2) {
+  ["@attributes"]=>
+  array(1) {
+    ["id"]=>
+    string(5) "elem1"
+  }
+  ["elem1"]=>
+  object(simplexml_inherited)#%d (3) {
+    ["@attributes"]=>
+    array(1) {
+      ["attr1"]=>
+      string(5) "first"
+    }
+    ["comment"]=>
+    object(simplexml_inherited)#%d (0) {
+    }
+    ["elem2"]=>
+    object(simplexml_inherited)#%d (1) {
+      ["elem3"]=>
+      object(simplexml_inherited)#%d (1) {
+        ["elem4"]=>
+        object(simplexml_inherited)#%d (1) {
+          ["test"]=>
+          object(simplexml_inherited)#%d (0) {
+          }
+        }
+      }
+    }
+  }
+}
 ===DONE===
index f48c9f1eecaa0fca435ce8bafbcf05a5b534c779..74ea4705cad0838ac6243b314d8024dde1e9503e 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and echo/print
+SimpleXML: echo/print
 --SKIPIF--
 <?php 
        if (!extension_loaded('simplexml')) print 'skip';
index 79c01107fe8768d1b7595af5f41f2b49e6104583..e5ebe2d09c3ec2cfb4680ee1cf7af7d764224e4b 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and Attribute creation
+SimpleXML: Attribute creation
 --SKIPIF--
 <?php 
        if (!extension_loaded('simplexml')) print 'skip';
index fbd80b0c446ef9149b60314e11a23151ad86f599..56c57dfbc2f59914189231e4eea8147366696c8e 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and Split text content
+SimpleXML: Split text content
 --SKIPIF--
 <?php 
        if (!extension_loaded('simplexml')) print 'skip';
index 9376b93e8ef9c7a7ceb3c9ac0fae12401c845783..2f58707d7d63ae3f4e01faad0f7b216a22a738b2 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and foreach with children()
+SimpleXML: foreach with children()
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
index a2a328736cc9c60ac69ac6c3cf25af8ff400437a..9e91b5ac3a976cff8250c87b57fe94cf4d9450a7 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML attribute compared to string
+SimpleXML: Attribute compared to string
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?> 
 --FILE--
index e58e26d6ee20c311babd4a8167acc1ce315e4173..d5138685f5e12da0a400d66ea19a3cbec3b9c278 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML element check
+SimpleXML: Element check
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?> 
 --FILE--
index 4a646205d5a233c67ea80a3eecf795625b4c2fa4..2af4a1dd280fd7b9fa57640fedeb59b2cc1ee9e8 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SimpleXML and attributes inside foreach
+SimpleXML: Attributes inside foreach
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 --FILE--
@@ -12,6 +12,13 @@ EOF;
 
 $sxe = simplexml_load_string($xml);
 
+echo "===CONTENT===\n";
+var_dump($sxe->content);
+
+echo "===FILE===\n";
+var_dump($sxe->content->file);
+
+echo "===FOREACH===\n";
 foreach($sxe->content->file as $file)
 {
        var_dump($file);
@@ -21,18 +28,35 @@ foreach($sxe->content->file as $file)
 ?>
 ===DONE===
 --EXPECTF--
-object(SimpleXMLElement)#%d (0) {
+===CONTENT===
+object(SimpleXMLElement)#%d (1) {
+  ["file"]=>
+  object(SimpleXMLElement)#%d (1) {
+    ["@attributes"]=>
+    array(1) {
+      ["glob"]=>
+      string(11) "slide_*.xml"
+    }
+  }
 }
+===FILE===
 object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  string(11) "slide_*.xml"
+  ["@attributes"]=>
+  array(1) {
+    ["glob"]=>
+    string(11) "slide_*.xml"
+  }
 }
-===DONE===
---UEXPECTF--
-object(SimpleXMLElement)#%d (0) {
+===FOREACH===
+object(SimpleXMLElement)#%d (1) {
+  ["@attributes"]=>
+  array(1) {
+    ["glob"]=>
+    string(11) "slide_*.xml"
+  }
 }
 object(SimpleXMLElement)#%d (1) {
   [0]=>
-  unicode(11) "slide_*.xml"
+  string(11) "slide_*.xml"
 }
 ===DONE===
index dd6dde59d78a57368e93956056ebcac01a71e87d..515a1460c9d4f41a67a4e8b0b526c3958cceac5a 100755 (executable)
@@ -22,7 +22,12 @@ var_dump($sxe['attr']);
 ?>
 ===DONE===
 --EXPECTF--
-object(SimpleXMLElement)#%d (0) {
+object(SimpleXMLElement)#%d (1) {
+  ["@attributes"]=>
+  array(1) {
+    ["attr"]=>
+    string(%d) "foo%sbar%sbaz"
+  }
 }
 object(SimpleXMLElement)#%d (1) {
   [0]=>
index 9ba9f7b6bd38984783521057832d7dab03370d1c..8649eb4fe63c641fa191a42ba7f67abc4e7650a3 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-#27010: segfault and node text not displayed when returned from children()
+Bug #27010: segfault and node text not displayed when returned from children()
 --FILE--
 <?php
 
index e68e6bd510ef90e5d421fd2bbe5dc09db28a057a..54c31bf7101e113dbf7d2f805e6cffdc92247e84 100644 (file)
@@ -12,15 +12,24 @@ $root = simplexml_load_string('<?xml version="1.0"?>
 </root>
 ');
 
-echo $root->children('reserved-ns')->child;
-echo "\n";
-echo $root->children('special-ns')->child;
-foreach ($root->child as $child) {
-       echo "$child\n";
-}
-echo "\n---Done---\n";
+var_dump($root->children('reserved-ns')->child);
+var_dump($root->children('special-ns')->child);
+var_dump((string)$root->children('reserved-ns')->child);
+var_dump((string)$root->children('special-ns')->child);
+var_dump($root->child);
 ?>
---EXPECT--
-Hello
-World
----Done--- 
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (1) {
+  [0]=>
+  string(5) "Hello"
+}
+object(SimpleXMLElement)#%d (1) {
+  [0]=>
+  string(5) "World"
+}
+string(5) "Hello"
+string(5) "World"
+object(SimpleXMLElement)#%d (0) {
+}
+===DONE=== 
index c66ba8f087b649af9970ac2cc0753c4f9d86b135..76e7f041dd5a1ac2ca723aaa5ecd085670d3dc4e 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-Interop: simplexml_import_dom
+SimpleXML [interop]: simplexml_import_dom
 --SKIPIF--
 <?php if (!extension_loaded("simplexml")) print "skip"; ?>
 <?php if (!extension_loaded("dom")) print "skip. dom extension not loaded"; ?>
index 8a8dde4308a74cf1bf0a6c69fb3d9e5973ccb6d7..b75a7922b0909ecf5961a70405251d78e9d7ed91 100755 (executable)
@@ -1,21 +1,34 @@
 <?xml encoding='US-ASCII'?>\r
 \r
-<!ELEMENT sxe    elem1, elem 11>\r
+<!ELEMENT sxe    (elem1+, elem11, elem22*)>\r
 <!ATTLIST sxe    id     CDATA  #implied>\r
 \r
-<!ELEMENT elem1  elem2>\r
+<!ELEMENT elem1  elem2*>\r
 <!ATTLIST elem1  attr1  CDATA  #required\r
                  attr2  CDATA  "default>\r
 \r
-<!ELEMENT elem2  elem3>\r
-<!ATTLIST elem2>\r
+<!ELEMENT elem2  elem3*>\r
+<!ATTLIST elem2  att25  CDATA  #implied\r
+                 att42  CDATA  #implied>\r
 \r
-<!ELEMENT elem3  elem4>\r
+<!ELEMENT elem3  elem4*>\r
 <!ATTLIST elem3>\r
 \r
 <!ELEMENT elem4  EMPTY>\r
 <!ATTLIST elem4>\r
 \r
-<!ELEMENT elem11 EMPTY>\r
+<!ELEMENT elem11 elem111*>\r
 <!ATTLIST elem11>\r
 \r
+<!ELEMNET elem111 elem1111*>\r
+<!ATTLIST elem111>\r
+\r
+<!ELEMENT elem1111 EMPTY>\r
+<!ATTLIST elem1111>\r
+\r
+<!ELEMENT elem22 elem222*>\r
+<!ATTLIST elem22 attr22 CDATA #implied>\r
+\r
+<!ELEMENT elem222 EMPTY>\r
+<!ATTLIST elem222>\r
+\r