mkdir

FunctionParams and return types changed in PHP 8.0

Makes directory.

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

mkdir Function synopsis

mkdir(
    string $directory,
    int $permissions = 0777,
    bool $recursive = false,
    $context = null
  ): bool

Parameters

$directory

Typestring

The directory path. A URL can be used as a filename with this function if the allow_url_fopen has been enabled. See fopen for more details on how to specify the filename. See the for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

$permissions

OptionalTypeintDefault value0777

The permissions are 0777 by default, which means the widest possible access. For more information on permissions, read the details on the chmod page.

$recursive

OptionalTypeboolDefault valuefalse

If true, then any parent directories to the $directory specified will also be created, with the same permissions.

$context

OptionalDefault valuenull

Return value

Typebool

Returns true on success, false on failure

If the directory to be created already exists, that is considered an error
and `false` will still be returned.  Use [`is_dir`](/codex/is_dir) or
[`file_exists`](/codex/file_exists) to check if the directory already exists
before trying to create it.

Changes to the mkdir Function

PHP 8.0

  • Return type added: bool
  • Parameter name of parameter #1 changed: $pathname to $directory
  • Parameter type added for parameter #1 ($directory): string
  • Parameter name of parameter #2 changed: $mode to $permissions
  • Parameter type added for parameter #2 ($permissions): int
  • Parameter default value added for position #2 ($permissions): 0777
  • Parameter type added for parameter #3 ($recursive): bool
  • Parameter default value added for position #3 ($recursive): false
  • Parameter default value added for position #4 ($context): null
  mkdir(
-     $pathname,
+     string $directory,
-     $mode,
+     int $permissions = 0777,
-     $recursive,
+     bool $recursive = false,
-     $context
+     $context = null
-   )
+   ): bool

mkdir 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