Fun with interfaces (Iterator fun)
| From: | Andrey Hristov | Date: | Wed, 28 Jan 2004 14:57:47 +0000 |
| Subject: | Fun with interfaces (Iterator fun) | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-7374@lists.php.net to get a copy of this message | ||
Hi internals,
here goes some interface fun :
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.
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(){}
}
?>
Output :
PHP Fatal error: Class FubarProblem must implement interface Traversable as
part of either Iterator or IteratorAggregate in Unknown on line 0
regards,
Andrey