WhichBrowser / Parser-PHP

Browser sniffing gone too far — A useragent parser library for PHP
http://whichbrowser.net
MIT License
1.8k stars 237 forks source link

PHP 8.2 deprecations #676

Closed davidbehler closed 5 months ago

davidbehler commented 1 year ago

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?

ldebrouwer commented 1 year ago

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.

ldebrouwer commented 1 year ago

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
ldebrouwer commented 1 year ago

See https://github.com/WhichBrowser/Parser-PHP/pull/673

einpraegsam commented 1 year ago

Same issue here

marc-farre commented 1 year ago

Any update? Thanks!

nadar commented 1 year ago

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. :pray:

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 :+1:

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

diadal commented 1 year ago

any update on this?

smuglet commented 1 year ago

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....

mshariq84 commented 5 months ago

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)
{
NielsLeenheer commented 5 months ago

Fixed in the latest release