Edit report at https://bugs.php.net/bug.php?id=61808&edit=1
ID: 61808 Updated by: johan...@php.net Reported by: nanocaiordo at gmail dot com Summary: Could not implement interface Iterator -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related Operating System: Fedora 17 x86_64 PHP Version: 5.4.0 Block user comment: N Private report: N New Comment: In internal classes we can do many things more which aren't possible for user. The documentation is for users, and users can't implement traversable. To the second quote: "iterators" are an concept which can be implemented in different ways. In userspace code one can use the Iterator or IteratorAggregate interface, in C code one can use Traversable. It was decided to provide iterator support by using Traversale, not Iterator, as the class already provides different ways to work on the result set and adding Iterator's methods creates a more messy interface ... Previous Comments: ------------------------------------------------------------------------ [2012-04-22 08:57:00] nanocaiordo at gmail dot com I also noticed few mismatches spread in documentation and or code logic. ### Quote: http://www.php.net/manual/en/class.traversable.php "The Traversable interface: Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator." But then, "MySQLi_Result implements Traversable" ### Quote: http://php.net/manual/en/class.mysqli-result.php "5.4.0: Iterator support was added, as mysqli_result now implements Traversable." 1. Implementing Traversable doesn't provide Iterator support, instead clashes with it. 2. mysqli_result still doesn't include any of the "Iterator" methods ### . changes should be reverted. . or change it to "MySQLi_Result implements Iterator" and add all methods. . make the Traversable interface be liberally implemented. Cheers ------------------------------------------------------------------------ [2012-04-22 07:02:22] nanocaiordo at gmail dot com Good decision indeed. But a fatal error, even if natural in this case, will make it impossible to run on both 5.3.10 and 5.4. Not sure if in this case a E_WARNING or a E_DEPRECATED could be used instead. However, I just found it in the changelog as "MySQLi: Added iterator support in MySQLi. mysqli_result implements Traversable." Shouldn't be added somewhere in the "migration" changes. ------------------------------------------------------------------------ [2012-04-22 06:42:29] larue...@php.net as of PHP-5.4, MySQLi_Result implements Traversable, but not sure, whether this should be a bug. ------------------------------------------------------------------------ [2012-04-22 05:29:01] nanocaiordo at gmail dot com Description: ------------ I cannot find anything within changelogs, bug reportings and documentations relating to this issue. It works fine in php 5.3.10, but gives me fatal error in PHP 5.4. Test script: --------------- <?php error_reporting(E_ALL | E_DEPRECATED | E_STRICT); ini_set('display_errors', 1); interface Foo_SQL_Interface_Result extends ArrayAccess, Countable, Iterator { public function data_seek($offset); public function fetch_all($resulttype=MYSQLI_NUM); public function fetch_array(); public function fetch_assoc(); public function fetch_field_direct($offset); public function fetch_field(); public function fetch_fields(); public function fetch_object(); public function fetch_row(); public function field_seek($offset); public function free(); } class Foo_MySQLi_UseResult extends MySQLi_Result { function __construct(MySQLi $obj) { parent::__construct($obj); } public function fetch_array($type_cast=false) {} public function fetch_assoc($type_cast=false) {} public function fetch_row($type_cast=false) {} public function fetch_all($resulttype=MYSQLI_ASSOC, $type_cast=false) {} } class Foo_MySQLi_Result extends Foo_MySQLi_UseResult implements Foo_SQL_Interface_Result { public function data_seek($offset) {} public function fetch_field_direct($offset) {} public function field_seek($offset) {} # ArrayAccess public function offsetExists($k) {} public function offsetGet($k) {} public function offsetSet($k, $v) {} public function offsetUnset($k) {} # Countable public function count() {} # Iterator public function key() {} public function current() {} public function next() {} public function rewind() {} public function valid() {} } Actual result: -------------- Fatal error: Class Foo_MySQLi_Result could not implement interface Iterator in Unknown on line 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61808&edit=1