summaryrefslogtreecommitdiff
path: root/Zend/zend_interfaces.c
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 /Zend/zend_interfaces.c
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 'Zend/zend_interfaces.c')
-rw-r--r--Zend/zend_interfaces.c38
1 files changed, 6 insertions, 32 deletions
diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c
index e2e81ed326..16751549b4 100644
--- a/Zend/zend_interfaces.c
+++ b/Zend/zend_interfaces.c
@@ -195,7 +195,7 @@ static int zend_user_it_get_current_key_default(zend_object_iterator *_iter, cha
/* }}} */
/* {{{ zend_user_it_get_current_key */
-ZEND_API int zend_user_it_get_current_key(zend_object_iterator *_iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
+ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *key TSRMLS_DC)
{
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
@@ -203,42 +203,16 @@ ZEND_API int zend_user_it_get_current_key(zend_object_iterator *_iter, char **st
zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_key, "key", &retval);
- if (!retval) {
- *int_key = 0;
- if (!EG(exception))
- {
+ if (retval) {
+ ZVAL_ZVAL(key, retval, 1, 1);
+ } else {
+ if (!EG(exception)) {
zend_error(E_WARNING, "Nothing returned from %s::key()", iter->ce->name);
}
- return HASH_KEY_IS_LONG;
- }
- switch (Z_TYPE_P(retval)) {
- default:
- zend_error(E_WARNING, "Illegal type returned from %s::key()", iter->ce->name);
- case IS_NULL:
- *int_key = 0;
- zval_ptr_dtor(&retval);
- return HASH_KEY_IS_LONG;
-
- case IS_STRING:
- *str_key = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
- *str_key_len = Z_STRLEN_P(retval)+1;
- zval_ptr_dtor(&retval);
- return HASH_KEY_IS_STRING;
-
- case IS_DOUBLE:
- *int_key = (long)Z_DVAL_P(retval);
- zval_ptr_dtor(&retval);
- return HASH_KEY_IS_LONG;
- case IS_RESOURCE:
- case IS_BOOL:
- case IS_LONG:
- *int_key = (long)Z_LVAL_P(retval);
- zval_ptr_dtor(&retval);
- return HASH_KEY_IS_LONG;
+ ZVAL_LONG(key, 0);
}
}
-/* }}} */
/* {{{ zend_user_it_move_forward */
ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter TSRMLS_DC)