WhichBrowser / Parser-PHP

Browser sniffing gone too far — A useragent parser library for PHP

Home Page:http://whichbrowser.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP 8.2 deprecations

davidbehler opened this issue · comments

Not sure what the right format for issues is. Let me know if you need more/different information.

What's the issue?
When using this package with PHP 8.2, I get the following E_DEPRECATED notices:

Creation of dynamic property WhichBrowser\Analyser\Header\Useragent::$data is deprecated
Creation of dynamic property WhichBrowser\Analyser\Header\Useragent::$options is deprecated

How can this be fixed?
It should be as easy as adding the $data and $options to the class definition. There might be other classes that need to be updated despite the WhichBrowser\Analyser\Header\Useragentone.

Do you want me to send a pull request or is an update for 8.2 already in the works?

commented

We've run into the same issue, it'd be great to have this nipped in the bud. I'd be willing to help with the PR.

commented

I've identified another instance of dynamic property creation here;

PHP Deprecated:  Creation of dynamic property WhichBrowser\Model\Os::$build is deprecated in /var/www/html/vendor/whichbrowser/parser/src/Analyser/Header/Useragent/Os.php on line 609
commented

See #673

Same issue here

Any update? Thanks!

commented

since php 8.2 is getting more and more attention in the real world (https://packagist.org/php-statistics) it would be nice to see this merged. We have built and open source CMS which where the user login process relays on the verification of user agents using this library, so all the projects can not upgrade to php 8.2.

@NielsLeenheer maybe there is someone you could add as maintain user, in order to help whenever there is no or less time. This is something i would recommend any open source library which is a certain amount of downloads and is therefore relevant for the php eco system. 🙏

update #1: I just saw there is @mariotsi, maybe he can merge this PR?
update #2: The package is super duper relevant i would say! https://packagist.org/packages/whichbrowser/parser/stats 👍

Thanks for the great library and your time spending on this.

any update on this?

I've found a note about adding #[AllowDynamicProperties] (https://php.watch/versions/8.2/dynamic-properties-deprecated) before classes where they are encountered. But if WhichBrowser no longer being updated....

Tested on

PHP v8.2
whichbrowser/parser v2.1.7

file: vendor\whichbrowser\parser\src\Analyser\Header\Useragent.php

Change

class Useragent
{
use Useragent\Os, Useragent\Device, Useragent\Browser, Useragent\Application, Useragent\Using, Useragent\Engine, Useragent\Bot;

// Initialize $data and $options properties
public function __construct($header, &$data, &$options)
{

To

class Useragent
{
use Useragent\Os, Useragent\Device, Useragent\Browser, Useragent\Application, Useragent\Using, Useragent\Engine, Useragent\Bot;

// Initialize $data and $options properties
private $data;
private $options;

public function __construct($header, &$data, &$options)
{

Fixed in the latest release