Where does this method come from

I am currently working through php how to order and is a bit puzzled by the following. Code Part:

$filesInFolder = new DirectoryIterator( $folder);
$file = $filesInFolder->current();
$filename = $file->getFilename();

I (think I) understand what $filesInFolder = new DirectoryIterator( $folder)creates a new instance DirectoryIterator( $folder)in $filesInFolderand what $file = $filesInFolder->current()calls the current()in method in $file.

I do not understand where the method comes getFilename()from $file->getFilename().

Is $file = $filesInFolder->current()creating a new instance of the class in, $fileor is something else happening?

thank

+4
source share
2 answers

Your question is quite correct. This is really confusing. What else, the receiving step ->current()can be omitted. This will also work:

$filesInFolder = new DirectoryIterator( $folder);
$filename = $filesInFolder->getFilename();

DirectoryIterator current:

DirectoryIterator.

current Iterator.

, , DirectoryIterator::current, DirectoryIterator. , :

, , current, , Iterable.

NB: Iterable :

foreach (new DirectoryIterator( $folder) as $file) {
    $filename = $file->getFilename();
    // ... etc, maybe break;
}

, , .

+1
  • DirectoryIterator

    $filesInFolder = new DirectoryIterator($folder);
    
  • DirectoryIterator ( ), $filesInFolder

    $file = $filesInFolder->current();
    
  • DirectoryIterator, $file.

    $filename = $file->getFilename();
    
0

All Articles