note 124370 added to splfileinfo.setinfoclass
| From: | EugeneKunkel@php.net | Date: | Tue, 05 Nov 2019 15:21:59 +0000 |
| Subject: | note 124370 added to splfileinfo.setinfoclass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-212948@lists.php.net to get a copy of this message | ||
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)
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 97.95.134.95)
----
Manual Page -- http://php.net/manual/en/splfileinfo.setinfoclass.php
Edit -- https://master.php.net/note/edit/124370
Del: integrated -- https://master.php.net/note/delete/124370/integrated
Del: useless -- https://master.php.net/note/delete/124370/useless
Del: bad code -- https://master.php.net/note/delete/124370/bad+code
Del: spam -- https://master.php.net/note/delete/124370/spam
Del: non-english -- https://master.php.net/note/delete/124370/non-english
Del: in docs -- https://master.php.net/note/delete/124370/in+docs
Del: other reasons-- https://master.php.net/note/delete/124370
Reject -- https://master.php.net/note/reject/124370
Search -- https://master.php.net/manage/user-notes.php