php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28217 casting RecursiveDirectoryIterator is bogus
Submitted: 2004-04-29 16:57 UTC Modified: 2004-04-29 23:11 UTC
From: nlopess@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2004-04-29 (dev) OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nlopess@php.net
New email:
PHP Version: OS:

 

 [2004-04-29 16:57 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-29 23:08 UTC] 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 23:11 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

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().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 01:01:28 2024 UTC