Jochem Maas wrote:
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....?"
Most of my question was stemming from the fact that I was working with DirectoryIterator for the first time, and thought the filename was the output, not an object. My first attempt at seeing it was working was just to echo $oFile (which, btw, was $sFile at that point). When I went to add in the 'hidden.txt' check, it didn't work as expected.
Ahhh, I realize __toString is still in it's infancy (relatively). I remember first hearing about it awhile back, then attempting to use it in a class I was writing at the time. It wasn't working as expected, and the fact that it was working in the DirectoryIterator caught me off guard.
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);
Thanks for the reponse. Seems like I'll need to further investigate it's uses.
http://www.php.net/oop5.magic
Chris
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php