stat

FunctionParams and return types changed in PHP 8.0

Gives information about a file.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

stat Function synopsis

stat(string $filename): array|false

Parameters

$filename

Typestring

Path to the file.

Return value

Typearray|false

  • On Windows this will always be 0.

    ** Only valid on systems supporting the st_blksize type - other systems (e.g. Windows) return -1.

    * On Windows, as of PHP 7.4.0, this is the serial number of the volume that contains the file, which is a 64-bit unsigned** integer, so may overflow. Previously, it was the numeric representation of the drive letter (e.g. 2 for C:) for stat, and 0 for lstat.

    ** On Windows, as of PHP 7.4.0, this is the identifier associated with the file, which is a 64-bit unsigned** integer, so may overflow. Previously, it was always 0.

    ***** On Windows, the writable permission bit is set according to the read-only file attribute, and the same value is reported for all users, group and owner. The ACL is not taken into account, contrary to is_writable.

    The value of mode contains information read by several functions. When written in octal, starting from the right, the first three digits are returned by chmod. The next digit is ignored by PHP. The next two digits indicate the file type:

    So for example a regular file could be 0100644 and a directory could be 0040755.

    In case of error, stat returns false.

Changes to the stat Function

PHP 8.0

  • Return type added: array|false
  • Parameter type added for parameter #1 ($filename): string
- stat($filename)
+ stat(string $filename): array|false

stat Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes