Currently the definition for file_copy is:
file_copy(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
Where as the file_unmanaged_copy is:
file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
The difference is subtle and easily missed but $source in file_copy must be an object while the $source in file_unmanaged_copy must be a string. For consistency reasons, these should be the same type.
Comments
Comment #1
marcingy CreditAttribution: marcingy commentedMoving to d8 as we deal with issue in head first and although a wtf nothing is actually broken so marking as a task.
Comment #8
alexpottI think
file_copy()
is badly named - it is an operation on a File object andfile_unmanaged_copy()
is an operation on the file as it is on disk not a Drupal entity so there's never really a time when these two can be the same thing. In D8 HEADfile_unmanaged_copy()
has been deprecated in favour of\Drupal\Core\File\FileSystemInterface::copy()
. Now that the two methods are not sitting next to each other the issue is less prominent and doesn't stick out. Hopefully eventually efforts like #2229865: [meta] Modernize File/StreamWrapper API will lead to file_copy(), file_move() etc will become part of the File entity or a service for managing File entities.