Be careful when using this method, as the functionality isn't exactly the same as instantiating the extending class directly. This can really trip you up if you're using type hints or instanceof checks.
<?php
class CustomFileInfo extends SplFileInfo
{
public function getExtension()
{
$ext = strtolower(parent::getExtension());
return 'jpeg' === $ext ? 'jpg' : $ext;
}
}
$path = __DIR__ . '/foobar.jpeg';
$good = new CustomFileInfo($path);
echo "<pre>";
var_dump($good instanceof SplFileInfo);
var_dump($good instanceof CustomFileInfo);
$bad = new SplFileInfo($path);
$bad->setInfoClass('CustomFileInfo');
var_dump($bad instanceof SplFileInfo);
var_dump($bad instanceof CustomFileInfo);
echo "</pre>";
?>
Outputs:
bool(true)
bool(true)
bool(true)
bool(false)