- var_dump: documentation ( source)
- end: documentation ( source)
- explode: documentation ( source)
- method_exists: documentation ( source)
<?php
class MySpl extends SplFileInfo
{
public function getExtension()
{
if (method_exists('SplFileInfo', 'getExtension')) {
return parent::getExtension();
}
$parts = explode('.', parent::getPathname());
if (!count($parts)) {
return "";
}
return end($parts);
}
}
foreach (array('foo.bar', 'baz.tar.gz', '/usr/bin/php', 'foo') as $file) {
$spl = new MySpl($file);
var_dump($spl->getExtension());
}