Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Breaking this off from #1191236: Correct file_copy, file_move, file_save_data, and drupal_realpath to match documentation and their unmanaged counterparts.
The documentation for the $destination
parameter to file_copy()
say, in part:
If this value is omitted, Drupal's default files scheme will be used, usually "public://".
However, this claim is untrue. Omitting the $destination parameter will actually result in the following code being executed:
watchdog('file', 'File %file (%realpath) could not be copied, because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->uri, '%realpath' => drupal_realpath($\
source->uri), '%destination' => $destination));
drupal_set_message(t('The specified file %file could not be copied, because the destination is invalid. More information is available in the system log.', array('%file' => $source->uri)), 'error');
return FALSE;
Comment | File | Size | Author |
---|---|---|---|
#4 | file_copy-make_docs_match_code-1192440-4.patch | 1.07 KB | pillarsdotnet |
#1 | file_copy-make_docs_match_code-1192440-1.patch | 1.16 KB | pillarsdotnet |
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedThe following patch corrects the documentation to match the code.
Comment #2
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #3
jhodgdonI don't think it's necessary to say what happens if the value is omitted. Just say it's required, or better yet just don't say anything, because we all know that PHP function arguments are generally required unless they are stated to be optional. We don't want to set a precedent of documenting what happens if people leave out required args in every function in Drupal.
Comment #4
pillarsdotnet CreditAttribution: pillarsdotnet commentedCorrected as suggested. See also alternative proposal #1192446: Make code of file_copy() match docs.
Comment #5
jhodgdonLooks fine.
Comment #6
webchickCommitted to 8.x and 7.x. Thanks!