feat(PHP): add deleteFolderRecursive sample#2217
Conversation
This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket. Fixes: b/521168740
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new PHP sample, delete_folder_recursive.php, which demonstrates how to recursively delete a folder and its contents in Cloud Storage, along with an integration test in StorageControlTest.php. The reviewer suggested a defensive programming improvement to ensure $operation->getError() is not null before calling getMessage(), preventing potential runtime errors if the error object is missing.
| } else { | ||
| printf('Failed to delete folder: %s', $operation->getError()->getMessage()); | ||
| } |
There was a problem hiding this comment.
To prevent potential null pointer/member function call on null errors, it is safer to check if $operation->getError() is not null before calling getMessage(). Although an error is expected when operationSucceeded() is false, defensive programming ensures robustness against unexpected API response formats.
} else {
$error = $operation->getError();
printf('Failed to delete folder: %s', $error ? $error->getMessage() : 'Unknown error');
}…lderRecursive [Generated-by: AI]
[Generated-by: AI]
This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.
Fixes: b/521168740