Skip to content

feat(PHP): add deleteFolderRecursive sample#2217

Draft
nidhiii-27 wants to merge 3 commits into
mainfrom
feat/php-delete-folder-recursive
Draft

feat(PHP): add deleteFolderRecursive sample#2217
nidhiii-27 wants to merge 3 commits into
mainfrom
feat/php-delete-folder-recursive

Conversation

@nidhiii-27

Copy link
Copy Markdown

This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.

Fixes: b/521168740

This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.

Fixes: b/521168740
@nidhiii-27 nidhiii-27 requested review from a team as code owners June 11, 2026 10:55
@snippet-bot

snippet-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Jun 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +55 to +57
} else {
printf('Failed to delete folder: %s', $operation->getError()->getMessage());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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');
    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nidhiii-27 nidhiii-27 marked this pull request as draft June 11, 2026 11:00
@nidhiii-27 nidhiii-27 added ai-generated Generated by AI storage-sample-architect Generated by storage-sample-architect skill labels Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Generated by AI samples Issues that are directly related to samples. storage-sample-architect Generated by storage-sample-architect skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant