helly Mon Oct 3 06:08:59 2005 EDT Modified files: /php-src/ext/spl spl_iterators.c Log: - Allow to use currnet() and key() in __toString() http://cvs.php.net/diff.php/php-src/ext/spl/spl_iterators.c?r1=1.86&r2=1.87&ty=u Index: php-src/ext/spl/spl_iterators.c diff -u php-src/ext/spl/spl_iterators.c:1.86 php-src/ext/spl/spl_iterators.c:1.87 --- php-src/ext/spl/spl_iterators.c:1.86 Sun Sep 25 08:01:31 2005 +++ php-src/ext/spl/spl_iterators.c Mon Oct 3 06:08:56 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_iterators.c,v 1.86 2005/09/25 12:01:31 helly Exp $ */ +/* $Id: spl_iterators.c,v 1.87 2005/10/03 10:08:56 helly Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -850,6 +850,12 @@ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); return NULL; } + if (((flags & CIT_CALL_TOSTRING) && (flags & (CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT))) + || ((flags & (CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT)) == (CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT))) { + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + zend_throw_exception(U_CLASS_ENTRY(spl_ce_InvalidArgumentException), "Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT", 0 TSRMLS_CC); + return NULL; + } intern->u.caching.flags |= flags & CIT_PUBLIC; MAKE_STD_ZVAL(intern->u.caching.zcache); array_init(intern->u.caching.zcache); @@ -1630,9 +1636,22 @@ intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - if (!(intern->u.caching.flags & CIT_CALL_TOSTRING)) { + if (!(intern->u.caching.flags & (CIT_CALL_TOSTRING|CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT))) { zend_throw_exception_ex(U_CLASS_ENTRY(spl_ce_BadMethodCallException), 0 TSRMLS_CC, "%v does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); } + if (intern->u.caching.flags & CIT_TOSTRING_USE_KEY) { + if (intern->current.key_type == HASH_KEY_IS_STRING) { + RETURN_STRINGL(intern->current.str_key, intern->current.str_key_len, 1); + } else { + RETVAL_LONG(intern->current.int_key); + convert_to_string(return_value); + return; + } + } else if (intern->u.caching.flags & CIT_TOSTRING_USE_CURRENT) { + RETVAL_ZVAL(intern->current.data, 1, 0); + + return; + } if (intern->u.caching.zstr) { *return_value = *intern->u.caching.zstr; zval_copy_ctor(return_value); @@ -1768,6 +1787,11 @@ return; } + if (((flags & CIT_CALL_TOSTRING) && (flags & (CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT))) + || ((flags & (CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT)) == (CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT))) { + zend_throw_exception(spl_ce_InvalidArgumentException , "Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT", 0 TSRMLS_CC); + return; + } if ((intern->u.caching.flags & CIT_CALL_TOSTRING) != 0 && (flags & ~CIT_CALL_TOSTRING) == 0) { zend_throw_exception(U_CLASS_ENTRY(spl_ce_InvalidArgumentException), "Unsetting flag CALL_TO_STRING is not possible", 0 TSRMLS_CC); return;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php