#28217 [Fbk->Bgs]: casting RecursiveDirectoryIterator is bogus
| From: | helly@php.net | Date: | Thu, 29 Apr 2004 21:11:38 +0000 |
| Subject: | #28217 [Fbk->Bgs]: casting RecursiveDirectoryIterator is bogus | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-59031@lists.php.net to get a copy of this message | ||
ID: 28217
Updated by: helly@php.net
Reported By: nlopess@php.net
-Status: Feedback
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: n/a
PHP Version: 5CVS-2004-04-29 (dev)
New Comment:
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
No it should definitively not cast to a string because it would mean
that in a foreach iteration you would no longer have access to the
memebrs.
The problem is that we needed to disable autocasting using __tostring
for php 5.0. The class in question was designed to have that feature
and that won't be changed.
From a design perspective the idea is to have the object work as an
inner iterator. That means the objects is always it own current eleemnt
because when used as an iterator it changes it's own state upon calling
rewind() or next().
Previous Comments:
------------------------------------------------------------------------
[2004-04-29 23:08:14] helly@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc.
If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.
------------------------------------------------------------------------
[2004-04-29 16:57:11] nlopess@php.net
Description:
------------
Just the check the following line in the reproduce code:
if($it->isDir() && !$it->isDot() && $it->current() != 'CVS') {
if you don't cast $it->current to a string it will output an error, so
I need to write:
if($it->isDir() && !$it->isDot() && (string) $it->current() !=
'CVS')
{
This should really cast it to a string automatically.
Reproduce code:
---------------
<?php
function recurse($it) {
for( ; $it->valid(); $it->next()) {
if($it->isDir() && !$it->isDot() && $it->current() != 'CVS') {
echo $it->current() . "\n";
if($it->hasChildren()) {
recurse($it->getChildren());
}
} elseif($it->isFile() && $it->current() != '.cvsignore') {
if(!php_check_syntax($it->current())) {
echo $it->current();
}
}
}
}
recurse(new RecursiveDirectoryIterator('phpdoc/en'));
?>
Actual result:
--------------
Notice: Object of class RecursiveDirectoryIterator could not be
converted to int
eger in c:\cvs\recurse.php on line 4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28217&edit=1