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

[bug]Fatal error: Declaration of Detection\Cache\CacheItem::expiresAt(?DateTimeInterface $expiration): Theme must be compatible with Psr\Cache\CacheItemInterface::expiresAt($expiration) #979

Open
BackuPs opened this issue Jan 25, 2025 · 2 comments
Assignees

Comments

@BackuPs
Copy link

BackuPs commented Jan 25, 2025

Describe the bug
A clear and concise description of what the bug is.
Include steps to reproduce the behavior.
A clear and concise description of what you expected to happen.

User-agent/Device/Phone/Tablet (please complete the following information):

  • User-agent [e.g. "Mozilla/5.0 (Linux; Android 12; SAMSUNG SM-F926B) AppleWebKit/537.36..."]

I get this error just on one website. PHP 8.2.27

Fatal error: Declaration of Detection\Cache\CacheItem::expiresAt(?DateTimeInterface $expiration): Theme must be compatible with Psr\Cache\CacheItemInterface::expiresAt($expiration) n /home/public_html/wp-content/themes/champion/framework/plugins/mobile-detect/src/Cache/CacheItem.php on line 100

Any idea how to fix this?

Using the standalone version.

@ArchBlood
Copy link

@BackuPs seems to me that it isn't accepting DateTime properly, you could offset this by changing it to one of the following;

public function expiresAt(?DateTimeInterface $expiration): static
{
    $this->expiresAt = $expiration;
    return $this;
}

Or properly use the following;

public function expiresAt(?DateTimeInterface $expiration): static
{
    $this->expiresAt = $expiration instanceof DateTimeImmutable 
        ? DateTime::createFromImmutable($expiration) 
        : $expiration;
    return $this;
}

The second option however may include performance overhead due to conversion. Overall the package in many areas either doesn't fully comply with PSR-16 or ignores requirements when implementing an interface. 🤔

@BackuPs
Copy link
Author

BackuPs commented Feb 8, 2025

@ArchBlood

On the same server many website are using the same code and do not have the issue. I stripped out the caching from the plugin as i dont need it.

Thank anyway for your solution. I will try it in that website that has the error.

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

No branches or pull requests

3 participants