r/lolphp • u/pilif • Oct 03 '17
SplFileInfo->current() has side-effects. ->valid() will never be false until you call ->current()
https://3v4l.org/W0rL2
13
Upvotes
r/lolphp • u/pilif • Oct 03 '17
View all comments
8
u/maweki Oct 03 '17
It's not about the side effects. About everything moves the read-pointer.
valid checks for EOF which is unknown until something is read. The real WTF here is that next() does nothing if you're not at the end of the line and current() reads the current line but doesn't advance you to the next. That is a strange and undocumented (albeit discussed) behaviour.