$filename
in that answer is actually not a string. It is an object of type SplFileInfo
which can be used like a string but it also offers much more detailed info:
SplFileInfo::getFilename()
-- filename.SplFileInfo::getPathname()
-- path to the fileSplFileInfo::getPathInfo()
-- SplFileInfo object for the pathSplFileInfo::getRealPath()
-- canonicalized absolute pathname; seerealpath()
for more info and the difference to Pathname,