php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41942 array() does not implement Traversable
Submitted: 2007-07-09 18:55 UTC Modified: 2007-07-23 23:14 UTC
From: justin dot hendrickson+bugs dot php dot net at gmail dot co Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.3 OS: Any
Private report: No CVE-ID: None
 [2007-07-09 18:55 UTC] justin dot hendrickson+bugs dot php dot net at gmail dot co
Description:
------------
Passing an array as a parameter with a type hint of Traversable causes a fatal error. I'd be nice if the basic array type could implement this interface so it can be used like this.

It appears this request is a duplicate of 33891, however it doesn't not appear to have any activity for almost 1 year.

Reproduce code:
---------------
function traversableTest(Traversable $items) {
    foreach($items as $item) {
        echo $item;
    }
}

traversableTest(array('one', 'two', 'three'));

Expected result:
----------------
onetwothree


Actual result:
--------------
Catchable fatal error: Argument 1 passed to traversableTest() must implement interface Traversable, array given, called in /home/jhendric/public_html/test.php on line 8 and defined in /home/jhendric/public_html/test.php on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-23 23:14 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Arrays are no objects thus they cannot implement an interface.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 16:01:31 2024 UTC