The solution was already introduced in 5.4 by Etienne Kneuss and Pierre but wasn't merged back into 5.3 . SplFileObject should not be used with directories. So just putting together all the necessary pieces from 5.4