static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC);
static zend_object_value php_sxe_register_object(php_sxe_object * TSRMLS_DC);
+static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data TSRMLS_DC);
+static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, int use_data TSRMLS_DC);
/* {{{ _node_as_zval()
*/
xmlNodePtr retnode = NULL;
if (sxe && sxe->iter.type != SXE_ITER_NONE) {
- php_sxe_reset_iterator(sxe TSRMLS_CC);
+ php_sxe_reset_iterator(sxe, 1 TSRMLS_CC);
if (sxe->iter.data) {
intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
GET_NODE(intern, retnode)
}
/* }}} */
+static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
+{
+ php_sxe_object *sxe;
+ xmlNodePtr node;
+
+ *count = 0;
+ sxe = php_sxe_fetch_object(object TSRMLS_CC);
+ node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC);
+
+ while (node)
+ {
+ (*count)++;
+ node = php_sxe_iterator_fetch(sxe, node->next, 0 TSRMLS_CC);
+ }
+
+
+ return SUCCESS;
+}
+/* }}} */
+
static zval *sxe_get_value(zval *z TSRMLS_DC)
{
zval *retval;
NULL, /* zend_get_std_object_handlers()->get_class_name,*/
sxe_objects_compare,
sxe_object_cast,
- NULL
+ sxe_count_elements
};
static zend_object_handlers sxe_ze1_object_handlers = {
NULL, /* zend_get_std_object_handlers()->get_class_name,*/
sxe_objects_compare,
sxe_object_cast,
- NULL
+ sxe_count_elements
};
static zend_object_value sxe_object_ze1_clone(zval *zobject TSRMLS_DC)
php_sxe_iterator_rewind,
};
-static void php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node TSRMLS_DC)
+static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, int use_data TSRMLS_DC)
{
char *prefix = sxe->iter.nsprefix;
int test_elem = sxe->iter.type == SXE_ITER_ELEMENT && sxe->iter.name;
node = node->next;
}
- if (node) {
+ if (node && use_data) {
ALLOC_INIT_ZVAL(sxe->iter.data);
_node_as_zval(sxe, node, sxe->iter.data, SXE_ITER_NONE, NULL, sxe->iter.nsprefix TSRMLS_CC);
}
+
+ return node;
}
-ZEND_API void php_sxe_reset_iterator(php_sxe_object *sxe TSRMLS_DC)
+static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data TSRMLS_DC)
{
xmlNodePtr node;
case SXE_ITER_ATTRLIST:
node = (xmlNodePtr) node->properties;
}
- php_sxe_iterator_fetch(sxe, node TSRMLS_CC);
+ return php_sxe_iterator_fetch(sxe, node, use_data TSRMLS_CC);
}
+ return NULL;
}
zend_object_iterator *php_sxe_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC)
}
if (node) {
- php_sxe_iterator_fetch(sxe, node->next TSRMLS_CC);
+ php_sxe_iterator_fetch(sxe, node->next, 1 TSRMLS_CC);
}
}
php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
sxe = iterator->sxe;
- php_sxe_reset_iterator(sxe TSRMLS_CC);
+ php_sxe_reset_iterator(sxe, 1 TSRMLS_CC);
}
-
void *simplexml_export_node(zval *object TSRMLS_DC)
{
php_sxe_object *sxe;
echo "===$what\n";
eval("var_dump(isset(\$$what));");
eval("var_dump((bool)\$$what);");
+ eval("var_dump(count(\$$what));");
eval("var_dump(\$$what);");
}
===sxe
bool(true)
bool(true)
+int(3)
object(SimpleXMLElement)#%d (3) {
["@attributes"]=>
array(1) {
===sxe->elem1
bool(true)
bool(true)
+int(2)
object(SimpleXMLElement)#%d (3) {
["@attributes"]=>
array(2) {
===sxe->elem1[0]
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (3) {
["@attributes"]=>
array(2) {
===sxe->elem1[0]->elem2
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (2) {
["@attributes"]=>
array(2) {
===sxe->elem1[0]->elem2->bla
bool(false)
bool(false)
+int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem1[0]["attr1"]
bool(true)
bool(true)
+int(0)
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "first"
===sxe->elem1[0]->attr1
bool(false)
bool(false)
+int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem1[1]
bool(true)
bool(true)
+int(0)
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(2) {
===sxe->elem1[2]
bool(false)
bool(false)
+int(0)
NULL
===sxe->elem11
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (1) {
["elem111"]=>
object(SimpleXMLElement)#%d (1) {
===sxe->elem11->elem111
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (1) {
["elem1111"]=>
object(SimpleXMLElement)#%d (0) {
===sxe->elem11->elem111->elem1111
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem22
bool(false)
bool(false)
+int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem22->elem222
bool(false)
bool(false)
+int(0)
NULL
===sxe->elem22->attr22
bool(false)
bool(false)
+int(0)
NULL
===sxe->elem22["attr22"]
bool(false)
bool(false)
+int(0)
NULL
===DONE===
--UEXPECTF--
===sxe
bool(true)
bool(true)
+int(3)
object(SimpleXMLElement)#%d (3) {
[u"@attributes"]=>
array(1) {
===sxe->elem1
bool(true)
bool(true)
+int(2)
object(SimpleXMLElement)#%d (3) {
[u"@attributes"]=>
array(2) {
===sxe->elem1[0]
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (3) {
[u"@attributes"]=>
array(2) {
===sxe->elem1[0]->elem2
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (2) {
[u"@attributes"]=>
array(2) {
===sxe->elem1[0]->elem2->bla
bool(false)
bool(false)
+int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem1[0]->attr1
bool(false)
bool(false)
+int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem1[1]
bool(true)
bool(true)
+int(0)
object(SimpleXMLElement)#%d (1) {
[u"@attributes"]=>
array(2) {
===sxe->elem1[2]
bool(false)
bool(false)
+int(0)
NULL
===sxe->elem11
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (1) {
[u"elem111"]=>
object(SimpleXMLElement)#%d (1) {
===sxe->elem11->elem111
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (1) {
[u"elem1111"]=>
object(SimpleXMLElement)#%d (0) {
===sxe->elem11->elem111->elem1111
bool(true)
bool(true)
+int(1)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem22
bool(false)
bool(false)
+int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem22->elem222
bool(false)
bool(false)
+int(0)
NULL
===sxe->elem22->attr22
bool(false)
bool(false)
+int(0)
NULL
===sxe->elem22["attr22"]
bool(false)
bool(false)
+int(0)
NULL
===DONE===