3v4l.org

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

preferences:
38.15 ms | 402 KiB | 5 Q