I'm running a PHP script from CLI that user the DirectoryIterator::getExtension()
method in PHP.
The version of PHP I'm running under is 5.3.5, but I keep getting errors saying Fatal error: Call to undefined method DirectoryIterator::getExtension()
The script works fine in my local dev machine running PHP 5.3.6, with no errors. However, the page for DirectoryIterator::getExtension() in the PHP man has no mention of version.
Can anyone tell me what version I need to use this method?
This is a much simpler way to get the file extension, IMO:
<?php
$iterator = new DirectoryIterator($data_dir);
foreach($iterator as $entity) {
if($entity->isFile()) {
$file_extension = pathinfo($entity->getFilename(), PATHINFO_EXTENSION);
...
}
}
?>
From the documentation:
(No version information available, might only be in SVN)
It seems like the commit didn't make the PHP 5.3.5 build, but got into the 5.3.6 release. The page just hasn't been updated yet.
And as Mario pointed out, the 5.3.6 changelog mentions the addition:
- SPL extension:
- ...
- Added SplFileInfo::getExtension(). FR #48767. (Peter Cowburn)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With