CakeFest 2024: The Official CakePHP Conference

SplFileInfo::isFile

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

SplFileInfo::isFileУказывает, ссылается ли объект на обычный файл

Описание

public SplFileInfo::isFile(): bool

Проверяет, существует ли файл, на который ссылается объект SplFileInfo, и является ли он обычным файлом.

Список параметров

У этой функции нет параметров.

Возвращаемые значения

Возвращает true, если файл существует и является обычным файлом (а не ссылкой), false в противном случае.

Примеры

Пример #1 Пример использования SplFileInfo::isFile()

<?php
$info
= new SplFileInfo(__FILE__);
var_dump($info->isFile());

$info = new SplFileInfo(dirname(__FILE__));
var_dump($info->isFile());
?>

Вывод приведённого примера будет похож на:

bool(true)
bool(false)

add a note

User Contributed Notes 1 note

up
4
dev at mike dot pp dot ua
4 years ago
Documentation is a bit misleading.

SplFileInfo->isFile() and other classes (e.g. DirectoryIterator->isFile()) return TRUE for symlinks of files. Better use getType() method instead, which returns 'link' for symlinks.

This was reported long time ago - https://bugs.php.net/bug.php?id=72364 , but docs are still not fixed.
To Top