Req #33891 [Opn->Bgs]: make array a traversable
| From: | fa@php.net | Date: | Sat, 13 Mar 2010 17:17:57 +0000 |
| Subject: | Req #33891 [Opn->Bgs]: make array a traversable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-148585@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=33891&edit=1
ID: 33891
Updated by: fa@php.net
Reported by: marcos dot neves at gmail dot com
Summary: make array a traversable
-Status: Open
+Status: Bogus
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: any
PHP Version: 5.1.0b3
New Comment:
Please try 5.3.2 or 5.2.13.
Previous Comments:
------------------------------------------------------------------------
[2010-03-13 18:08:24] wrzasq at gmail dot com
It should also expose interfaces ArrayAccess and Countable. It's very
frustrating when you use type hinting to force iterable structures or
array-like accessible and it comes out that you can't pass array
themselves.
------------------------------------------------------------------------
[2005-07-27 22:14:08] marcos dot neves at gmail dot com
Description:
------------
Traversable is an internal interface that says "I can be used in a
foreach". Since array can be used too, would be nice if array be
accepted internally in parameters that expect traversable.
Reproduce code:
---------------
<?
function acceptArray(array $t) {
echo "\n".__FUNCTION__."\n";
foreach($t as $k=>$v) {
echo "$k=>$v\n";
}
}
function acceptTraversable(Traversable $t) {
echo "\n".__FUNCTION__."\n";
foreach($t as $k=>$v) {
echo "$k=>$v\n";
}
}
$test = array("is", "array", "traversable", "too",
"?");
acceptArray($test); // ok
acceptTraversable(new ArrayIterator($test)); // ok
acceptTraversable($test); // would be nice
?>
Expected result:
----------------
acceptTraversable($test); shoud accept an array, since it's too a
Traversable structure(can be used in a foreach).
Actual result:
--------------
Fatal error: Argument 1 must be an object of class Traversable
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=33891&edit=1