From:             marcos dot neves at gmail dot com
Operating system: any
PHP version:      5.1.0b3
PHP Bug Type:     Feature/Change Request
Bug description:  make array a traversable

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 bug report at http://bugs.php.net/?id=33891&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33891&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33891&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33891&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33891&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33891&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33891&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33891&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33891&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33891&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33891&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33891&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33891&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33891&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33891&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33891&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33891&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33891&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33891&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33891&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33891&r=mysqlcfg

Reply via email to