Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DirectoryIterator::getExtension() version

Tags:

php

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?

like image 640
julio Avatar asked Dec 14 '11 16:12

julio


2 Answers

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);
      ...
    }
  }
?>
like image 144
ebeyrent Avatar answered Oct 06 '22 13:10

ebeyrent


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)
like image 34
Tim Cooper Avatar answered Oct 06 '22 13:10

Tim Cooper