scandir

FunctionParams and return types changed in PHP 8.0

List files and directories inside the specified path.

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

scandir Function synopsis

scandir(
    string $directory,
    int $sorting_order = SCANDIR_SORT_ASCENDING,
    $context = null
  ): array|false

Parameters

$directory

Typestring

The directory that will be scanned.

$sorting_order

OptionalTypeintDefault valueSCANDIR_SORT_ASCENDING

By default, the sorted order is alphabetical in ascending order. If the optional $sorting_order is set to SCANDIR_SORT_DESCENDING, then the sort order is alphabetical in descending order. If it is set to SCANDIR_SORT_NONE then the result is unsorted.

$context

OptionalDefault valuenull

For a description of the $context parameter, refer to the streams section of the manual.

Return value

Typearray|false

Returns an array of filenames on success, or false on failure. If $directory is not a directory, then boolean false is returned, and an error of level E_WARNING is generated.

Changes to the scandir Function

PHP 8.0

  • Return type added: array|false
  • Parameter name of parameter #1 changed: $dir to $directory
  • Parameter type added for parameter #1 ($directory): string
  • Parameter type added for parameter #2 ($sorting_order): int
  • Parameter default value added for position #2 ($sorting_order): SCANDIR_SORT_ASCENDING
  • Parameter default value added for position #3 ($context): null
  scandir(
-     $dir,
+     string $directory,
-     $sorting_order,
+     int $sorting_order = SCANDIR_SORT_ASCENDING,
-     $context
+     $context = null
-   )
+   ): array|false

scandir 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