From: Marcus Boerger Date: Thu, 29 Apr 2004 07:22:02 +0000 (+0000) Subject: - Remove unused variable X-Git-Tag: RELEASE_0_1~335 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf5f758c9343d9fde7e8d6b94619a4ca3e2c0b56;p=php - Remove unused variable - Respect visibility in count() and add a test for that --- diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index a4a5465d7c..73063fe95d 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -723,18 +723,31 @@ SPL_METHOD(Array, seek) Return the number of elements in the Iterator. */ SPL_METHOD(Array, count) { - long position; zval *object = getThis(); spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); HashTable *aht = HASH_OF(intern->array); HashPosition pos; + long cnt; if (!aht) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); RETURN_LONG(0); } - RETURN_LONG(zend_hash_num_elements(aht)); + if (Z_TYPE_P(intern->array) == IS_OBJECT) { + pos = intern->pos; + cnt = 0; + zend_hash_internal_pointer_reset_ex(aht, &intern->pos); + while(intern->pos) { + cnt++; + spl_array_next(intern TSRMLS_CC); + } + intern->pos = pos; + RETURN_LONG(cnt); + } else { + RETURN_LONG(zend_hash_num_elements(aht)); + } + } /* }}} */ /* {{{ proto mixed|NULL ArrayIterator::current() diff --git a/ext/spl/tests/array_012.phpt b/ext/spl/tests/array_012.phpt new file mode 100755 index 0000000000..a8889654a5 --- /dev/null +++ b/ext/spl/tests/array_012.phpt @@ -0,0 +1,65 @@ +--TEST-- +SPL: ArrayIterator::count +--SKIPIF-- + +--FILE-- + 0, 'one' => 1, 'two' => 2); +$it = new ArrayIterator($a); + +var_dump($it->count()); +foreach($it as $key => $val) +{ + echo "$key=>$val\n"; + var_dump($it->count()); +} +var_dump($it->count()); + +echo "===Object===\n"; + +class test +{ + public $zero = 0; + protected $pro; + public $one = 1; + private $pri; + public $two = 2; +} + +$o = new test; +$it = new ArrayIterator($o); + +var_dump($it->count()); +foreach($it as $key => $val) +{ + echo "$key=>$val\n"; + var_dump($it->count()); +} +var_dump($it->count()); + +?> +===DONE=== + +--EXPECT-- +===Array=== +int(3) +zero=>0 +int(3) +one=>1 +int(3) +two=>2 +int(3) +int(3) +===Object=== +int(3) +zero=>0 +int(3) +one=>1 +int(3) +two=>2 +int(3) +int(3) +===DONE===