googleapis / google-api-php-client

A PHP client library for accessing Google APIs
http://googleapis.github.io/google-api-php-client/
Apache License 2.0
9.29k stars 3.52k forks source link

Aliases might be incompartible with PHP 7.4 Preloading feature #1976

Closed Ttakeleif closed 3 years ago

Ttakeleif commented 3 years ago

Environment details

Steps to reproduce

I have an issue with aliases in Symfony app optimized for PHP 7.4 preloading feature. It loads all the required classes at once and conflicts with the aliases file which leads to numerous errors like

Cannot declare class Google_Http_REST, because the name is already in use in /app/vendor/google/apiclient/src/aliases.php on line 27

Could you please make it optional or add checking that those classes are not defined yet?

For those who have the same issue possible solutions are

mfn commented 3 years ago

stick to 2.7.x (unfortunately not my case because I use it indirectly via lib with dependency like ^2.x)

Btw you can still "fix" this yourself my (temporary) making it a root dependency in your project for 2.7, so you wouldn't have to resort the build step. At least I would like to think so that this should work.

Ttakeleif commented 3 years ago

@mfn I solved the conflict by adding

    "require": {
        "google/apiclient": "2.7.2 as 2.8.0"
    }

to composer.json. Though I have to retest the functionality for any possible issues because of that blatant substitution 🤞 😄

bshaffer commented 3 years ago

Thank you for reporting this, I will look into how to fix it. In the meantime, you can just require google/apiclient:2.7.2 rather than use an alias for 2.8.0 as you do above:

    "require": {
        "google/apiclient": "2.7.2"
    }

The issue with your transitive dependency is you need to remove composer.lock and vendor before updating with the above require.

bshaffer commented 3 years ago

@Ttakeleif this is now fixed! Update to v.2.8.1 and you'll be all set!

Ttakeleif commented 3 years ago

@bshaffer I can confirm the issue is fixed.

snoogans235 commented 3 years ago

Does this mean the class_exists line in src/aliases.php is no longer needed?

Edit: Just saw this was the fix for this issue. I'm still getting a problem while running docker container php7.4-apache. I am able to avoid the issue by using 2.8.0 though.

bshaffer commented 3 years ago

@snoogans235 is it possible this will fix your issue?

https://github.com/googleapis/google-api-php-client/pull/1991

aliemam commented 3 years ago

@bshaffer Is this solved in 2.8.3? because I still get the warnings. PHP Warning: Can't preload already declared class Google_Utils_UriTemplate

kursez commented 3 years ago

I got the same issue again for 2.8.3

eugenekurasov commented 3 years ago

After merge PR preload send warnings. https://github.com/googleapis/google-api-php-client/pull/1995

nmeirik commented 3 years ago

I'm not sure that this fix has been sufficient. I am running v. 2.9.1 of "google/apiclient" and I get the following output:

  Can't preload already declared class Google_Utils_UriTemplate in /code/platform/vendor/go
 ogle/apiclient/src/aliases.php on line 64
  Can't preload already declared class Google_Task_Runner in /code/platform/vendor/google/a
 piclient/src/aliases.php on line 63
  Can't preload already declared class Google_Task_Retryable in /code/platform/vendor/googl
 e/apiclient/src/aliases.php on line 62
  Can't preload already declared class Google_Task_Exception in /code/platform/vendor/googl
 e/apiclient/src/aliases.php on line 61
  Can't preload already declared class Google_Service_Resource in /code/platform/vendor/goo
 gle/apiclient/src/aliases.php on line 60
  Can't preload already declared class Google_Service_Exception in /code/platform/vendor/go
 ogle/apiclient/src/aliases.php on line 59
  Can't preload already declared class Google_Service in /code/platform/vendor/google/apicl
 ient/src/aliases.php on line 58
  Can't preload already declared class Google_Model in /code/platform/vendor/google/apiclie
 nt/src/aliases.php on line 57
  Can't preload already declared class Google_Http_REST in /code/platform/vendor/google/api
 client/src/aliases.php on line 56
  Can't preload already declared class Google_Http_MediaFileUpload in /code/platform/vendor
 /google/apiclient/src/aliases.php on line 55
  Can't preload already declared class Google_Http_Batch in /code/platform/vendor/google/ap
 iclient/src/aliases.php on line 54
  Can't preload already declared class Google_Exception in /code/platform/vendor/google/api
 client/src/aliases.php on line 53
  Can't preload already declared class Google_Collection in /code/platform/vendor/google/ap
 iclient/src/aliases.php on line 52
  Can't preload already declared class Google_Client in /code/platform/vendor/google/apicli
 ent/src/aliases.php on line 51
  Can't preload already declared class Google_AuthHandler_Guzzle7AuthHandler in /code/platf
 orm/vendor/google/apiclient/src/aliases.php on line 50
  Can't preload already declared class Google_AuthHandler_Guzzle6AuthHandler in /code/platf
 orm/vendor/google/apiclient/src/aliases.php on line 49
  Can't preload already declared class Google_AuthHandler_Guzzle5AuthHandler in /code/platf
 orm/vendor/google/apiclient/src/aliases.php on line 48
  Can't preload already declared class Google_AuthHandler_AuthHandlerFactory in /code/platf
 orm/vendor/google/apiclient/src/aliases.php on line 47
  Can't preload already declared class Google_AccessToken_Verify in /code/platform/vendor/g
 oogle/apiclient/src/aliases.php on line 46

Can this issue perhaps be reopened?

hakimio commented 3 years ago

@nmeirik they fixed it in google\apiclient, but the same issue exists in google\apiclient-services library which is not fixed. My bug report.

EDIT: seems to be an issue on my end. I had left-over directory after composer vendor directory upload.

bshaffer commented 3 years ago

@nmeirik I missed your comment because this issue is closed. Were you able to get it resolved? If not can you open a new issue? Thanks.

nmeirik commented 3 years ago

@bshaffer I realized that is was just a warning and not a blocker as I initially thought, so I moved on.

rulatir commented 2 years ago

There is no such thing as "warning and not a blocker". Whenever you have warnings AND ALSO a crash for which you seek support, the first question you'll get asked is "are there any warnings"?