googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.2k stars 3.52k forks source link

docs: fix namespace slash problem #2587

Closed xialeistudio closed 2 months ago

xialeistudio commented 2 months ago

Hi Google Api PHP Client Team,

I found some problems with README.md. When I tried to integrate Oauth, I copied the code of README.md and I found an error that the class did not exist. I found out that it was because there was a missing slash. According to the PHP specification, a leading slash is required when using fully qualified class names.

So I started this PR to help others.

google-cla[bot] commented 2 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

bshaffer commented 2 months ago

The samples are not set in a namespace, so omitting the \ is appropriate. If your code file is namespaced, then the best practice would be to import the classes, not prefix them with a slash, e.g:

use Google\Client;

$client = new Client();
xialeistudio commented 2 months ago

The samples are not set in a namespace, so omitting the \ is appropriate. If your code file is namespaced, then the best practice would be to import the classes, not prefix them with a slash, e.g:

use Google\Client;

$client = new Client();

Understood, I believe this is an issue of document consistency, which may confuse users who are using the SDK for the first time. Therefore, I have submitted this PR to address the issue.