summaryrefslogtreecommitdiff
path: root/ext/dom
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2013-02-16 19:13:36 +0100
committerNikita Popov <nikic@php.net>2013-03-12 17:27:31 +0100
commitfcc6611de9054327441786e52444b5f8eecdd525 (patch)
tree072a133a6e3ea1c067d9ad30cb07bb8130691094 /ext/dom
parent8436342d8861650930f985249ce3da7f92f03506 (diff)
downloadphp-git-fcc6611de9054327441786e52444b5f8eecdd525.tar.gz
Add support for non-scalar Iterator keys in foreach
RFC: https://wiki.php.net/rfc/foreach-non-scalar-keys
Diffstat (limited to 'ext/dom')
-rw-r--r--ext/dom/dom_iterators.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c
index f4183d2f9a..6c8cf84e9f 100644
--- a/ext/dom/dom_iterators.c
+++ b/ext/dom/dom_iterators.c
@@ -157,35 +157,22 @@ static void php_dom_iterator_current_data(zend_object_iterator *iter, zval ***da
}
/* }}} */
-static int php_dom_iterator_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) /* {{{ */
+static void php_dom_iterator_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC) /* {{{ */
{
- zval *curobj;
- xmlNodePtr curnode = NULL;
- dom_object *intern;
- zval *object;
- int namelen;
-
php_dom_iterator *iterator = (php_dom_iterator *)iter;
-
- object = (zval *)iterator->intern.data;
+ zval *object = (zval *)iterator->intern.data;
if (instanceof_function(Z_OBJCE_P(object), dom_nodelist_class_entry TSRMLS_CC)) {
- *int_key = iter->index;
- return HASH_KEY_IS_LONG;
+ ZVAL_LONG(key, iter->index);
} else {
- curobj = iterator->curobj;
+ dom_object *intern = (dom_object *)zend_object_store_get_object(iterator->curobj TSRMLS_CC);
- intern = (dom_object *)zend_object_store_get_object(curobj TSRMLS_CC);
if (intern != NULL && intern->ptr != NULL) {
- curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node;
+ xmlNodePtr curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node;
+ ZVAL_STRINGL(key, (char *) curnode->name, xmlStrlen(curnode->name), 1);
} else {
- return HASH_KEY_NON_EXISTANT;
+ ZVAL_NULL(key);
}
-
- namelen = xmlStrlen(curnode->name);
- *str_key = estrndup(curnode->name, namelen);
- *str_key_len = namelen + 1;
- return HASH_KEY_IS_STRING;
}
}
/* }}} */