copy

FunctionParams and return types changed in PHP 8.0

Copies 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

copy Function synopsis

copy(
    string $from,
    string $to,
    $context = null
  ): bool

Parameters

$from

Typestring

Path to the source file.

$to

Typestring

The destination path. If $to is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files.

$context

OptionalDefault valuenull

A valid context resource created with stream_context_create.

Return value

Typebool

Returns true on success, false on failure

Changes to the copy Function

PHP 8.0

  • Return type added: bool
  • Parameter name of parameter #1 changed: $source_file to $from
  • Parameter type added for parameter #1 ($from): string
  • Parameter name of parameter #2 changed: $destination_file to $to
  • Parameter type added for parameter #2 ($to): string
  • Parameter default value added for position #3 ($context): null
  copy(
-     $source_file,
+     string $from,
-     $destination_file,
+     string $to,
-     $context
+     $context = null
-   )
+   ): bool

copy 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