Google-api-php-client: Google\Client vs. Google_Client

Created on 31 Oct 2020  路  6Comments  路  Source: googleapis/google-api-php-client

Recent versions need initialization as Google\Client, but many Services still need Google_Client class ?
Is there a difference and if, how to use both ?

question

Most helpful comment

Prefer Google\Client. Google_Client is still available via an alias, so all services will continue working as normal.

All 6 comments

Prefer Google\Client. Google_Client is still available via an alias, so all services will continue working as normal.

Using Google\Client will throw type warnings if using most services as there Google_Client is still used. So these can be ignored then ?

Here is a simple example showing the essentials of how the aliases work:

<?php

class A {}
class_alias("A", "B");

// for code completion.
if (false) {
    class B extends A {}
}

function impl(A $foo) {
    var_dump(is_a($foo, "A"));
}

impl(new B);

The if (false) {} block is added in #1984, which should be part of the next release, hopefully next week. If you're seeing errors it may be because your IDE does not know about the alias. Despite this, everything should work as expected when the code is executed. If you are having issues other than the one described in the linked issue, please provide an example!

@wrufeger where are you seeing warnings? This should not be the case. Can you provide us with an example and the warning message you're receiving?

In yii2 i get an error if using Google\Client , how to solve this?
FB_IMG_1605375417101

The IDE issue should now be fixed in v2.8.3. Please update to the latest version, and open a new issue if you continue to see this error!

Was this page helpful?
0 / 5 - 0 ratings