php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27073 Strange behaviour after extending interface Iterator wo adding anything new
Submitted: 2004-01-28 08:51 UTC Modified: 2006-01-02 09:04 UTC
Votes:4
Avg. Score:4.5 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: andrey@php.net Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0b3 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrey@php.net
New email:
PHP Version: OS:

 

 [2004-01-28 08:51 UTC] andrey@php.net
Description:
------------
See the code attached :
class FubarOK has no problem implementing Iterator. interface NewIterator just extends Iterator and adds nothing, and here comes the fun - an error message when FubarProblem tries to implement NewIterator.

Reproduce code:
---------------
<?php
class FubarOk implements Iterator {
        public function next(){}
        public function key(){}
        public function current(){}
        public function hasMore(){}
        public function rewind(){}
}

interface NewIterator extends Iterator {

}

class FubarProblem implements NewIterator {
        public function next(){}
        public function key(){}
        public function current(){}
        public function hasMore(){}
        public function rewind(){}
}
?>

Actual result:
--------------
PHP Fatal error:  Class FubarProblem must implement interface Traversable as
part of either Iterator or IteratorAggregate in Unknown on line 0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-05 07:54 UTC] andrey@php.net
I am still experiencing the problem : 

andrey@poohie:~/test> php -v
PHP 5.0.0RC1-dev (cli) (built: Feb  4 2004 17:26:46)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0-dev, Copyright (c) 1998-2004 Zend Technologies

andrey@poohie:~/test> php gg.php
PHP Fatal error:  Class FubarProblem must implement interface Traversable as part of either Iterator or IteratorAggregate in Unknown on line 0

 [2004-02-05 11:34 UTC] helly@php.net
This is something we may fix later but for now the following is enough:
class FubarProblem implements Iterator, NewIterator {
        public function next(){}
        public function key(){}
        public function current(){}
        public function hasMore(){}
        public function rewind(){}
}

As you see here the Iterator interface is inherited first so that the checks are done in the correct order.
 [2006-01-02 09:04 UTC] sniper@php.net
Error has changed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 17:01:29 2025 UTC