Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error: Declaration of Beste\Cache\InMemoryCache::getItem(string $key): Psr\Cache\CacheItemInterface must be compatible with PsrExt\Cache\CacheItemPoolInterface::getItem($key) in /vendor/beste/in-memory-cache/src/InMemoryCache.php on line 33 #5

Closed
davidbuzzard opened this issue Sep 9, 2024 · 10 comments

Comments

@davidbuzzard
Copy link

I'm trying to use the latest kreait/firebase-php which is using Beste\Cache\InMemoryCache by default. Following the setup instructions from https://firebase-php.readthedocs.io/en/7.14.0/setup.html (without auto-discovery) I'm getting following fatal error:

PHP Fatal error: Declaration of Beste\Cache\InMemoryCache::getItem(string $key): Psr\Cache\CacheItemInterface must be compatible with PsrExt\Cache\CacheItemPoolInterface::getItem($key) in /vendor/beste/in-memory-cache/src/InMemoryCache.php on line 33

What are my options? Thanks in advance!

@jeromegamez
Copy link
Member

jeromegamez commented Sep 9, 2024

Can you tell me where the PsrExt\Cache\CacheItemPoolInterface in the error comes from, specifically the PsrExt.

A full stack trace of the error would be helpful.

I'd need your PHP Version, your composer.json and a/the script how you invoke the SDK so that I can try to reproduce the problem.

Thanks!

@davidbuzzard
Copy link
Author

davidbuzzard commented Sep 10, 2024

Thank you very much for your fast response.

We are using php 8.1.29, composer.json was created just using composer require "kreait/firebase-php:^7.0", and the code using the SDK is limited to these few lines right now:

require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase\Factory;

$factory = (new Factory)->withServiceAccount(json-file-path);

I wish to know where exactly that error comes from as well, Sentry just shows line 33 in /vendor/beste/in-memory-cache/src/InMemoryCache.php as also mentioned in the error message itself. I'm afraid that's not the full stack trace we want. Is there code available I can temporally use to create one?

@jeromegamez
Copy link
Member

jeromegamez commented Sep 10, 2024

I tried reproducing the problem:

mkdir firebase-test
cd firebase-test
composer require kreait/firebase-php
composer require vlucas/phpdotenv

Create a .env file and add the GOOGLE_APPLICATION_CREDENTIALS variable, set it either with the path to your service account file, or the contents of the file. Use the file path if you try the following with your locally installed PHP, and the JSON string if you want to run it with docker.

# .env
GOOGLE_APPLICATION_CREDENTIALS=...

Create a test.php file with the following contents:

<?php
# test.php

declare(strict_types=1);

require 'vendor/autoload.php';

use Dotenv\Dotenv;
use Kreait\Firebase\Factory;

$dotenv = Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->safeLoad();

$factory = (new Factory);
$auth = $factory->createAuth();

foreach ($auth->listUsers() as $user) {
    echo "$user->uid\n";
    exit;
}

Then I ran

docker run --rm -it -v $(pwd):/app -w /app php:8.1-cli php test.php

or, with a locally installed PHP (8.3 in my case)

php test.php

This works for me - also, the CI Pipeline of the SDK is tested with PHP versions 8.1 to 8.4 and didn't report errors either.

Can you share more information about your environment, other dependencies you have in your project, the PHP version you're using, etc.

@davidbuzzard
Copy link
Author

Again thank you very much for your fast response as well as your extensive instructions for testing this. Unfortunately this leads to exactly the same fatal error message as before.

As I mentioned before we are using php 8.1.29. It's on Rocket Linux 8.10 (previously CentOS, based on RedHat Enterprise Linux). I've attached the CLI output for phpinfo(), I hope that may possibly already include a hint of what is be the issue.

Next week I can try this on different systems to try to narrow down possible settings that may cause this.

@tes123id
Copy link

i face the same issue.
I am using Phalcon v5, PHP v8.1.29 and latest kreait/firebase-php v7.15.

@jeromegamez
Copy link
Member

For the time being, could you please try requiring version 1.3.0 explicitly in your project's composer.json? I feel as if 1.3.1, which removes a notice in PHP 8.4 introduces the fatal in PHP 8.1, and I would like to confirm that. If that's the case, I'll have to revert 1.3.1 in 1.3.2 and create a new major release for PHP 8.4...

Sorry for the inconvenience!

@tes123id
Copy link

i face the same issue. I am using Phalcon v5, PHP v8.1.29 and latest kreait/firebase-php v7.15.

i have finally found the solution.
It turns out it's conflicted with psr module installed as dependancy to Phalcon 5 using apt repossitory ppa:ondrej/php
remove phalcon5 along with the psr module
and compile phalcon manually.

and it's working now.

@jeromegamez
Copy link
Member

Thanks for the insights, @tes123id - with your hint, I looked into this as well and found https://github.com/jbboehr/php-psr .

This then led me to symfony/symfony#48934 and laravel/framework#46165 (among others).

With this, I think this isn't something I can fix in code here - @davidbuzzard, if you remove the system package/module, you should get the needed classes/interface through the composer dependencies anyway.

Thanks again!

@jeromegamez
Copy link
Member

@davidbuzzard
Copy link
Author

Thanks a lot @tes123id and @jeromegamez for finding the cause!! No chance we'd ever found that...

Just for others finding this issue and using RHEL based distributions, you may want to do dnf remove php-pecl-psr to solve it. According to dnf repoquery --whatrequires php-pecl-psr only the package php-pecl-http-message depends on it. I guess we had that installed at some point, leaving php-pecl-psr as an orphan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants