Chris wrote:
I'm not sure if this is a feature request, a "Oh, I didn't know that",
or "That's the way it is, deal with it" kind of problem.
iMHO its pretty much the last one, but I don't see the problem
with what you have written, ok its a little longer, but you
don't have to know that the magic (see below) occurs in order to
understand the expression - i.e. $oFile->getFilename() is pretty
obvious :-), that nice when you get a call twelve months from now
"can you please....?"
foreach(new DirectoryIterator($sDir) as $oFile)
{
if($oFile->isDot() || 'hidden.txt' == $oFile->getFilename()) continue;
echo $oFile,"\n";
}
In the code above, I am echoing $oFile, which internally is recognizing
it's being used in a string context, so calling the __toString method on
itself (which then returns the result of ->getFilename()). Now, what my
question is, is why won't it do that when I'm comparing values?
'hidden.txt' == $oFile Is never true, because $oFile doesn't seem to
here you are comparing two things - what is there to say that the string
type has precedence (and therefore force $oFile to a string(cue magic))?
basically this is very hard to do correctly and so that everyone agrees
on how it should work exactly. AFAICT.
only echo & print trigger the magic at this point in time AFAICR.
---
class XYZ
{
function __toString() { return "xyz"; }
}
$x = new XYZ;$a = sprintf("%s",$x);
echo $x,"\n";var_dump($a);print($x);echo"\n";print_r($x);
recognize it's being compared in a string context.
I'm not sure I *want* it to do this, but at the moment I can't think of
any reason why it couldn't behave like this.
Any thoughts?
http://www.php.net/~helly/php/ext/spl/classDirectoryIterator.html
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php