Propaganistas/Laravel-Phone

PHP 8.1 deprecated issues

emaadali opened this issue · 7 comments

Cannot run this package on PHP 8.1. I get the following errors:

PHP Deprecated: Return type of Propaganistas\LaravelPhone\PhoneNumber::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/vendor/propaganistas/laravel-phone/src/PhoneNumber.php on line 375

PHP Deprecated: Propaganistas\LaravelPhone\PhoneNumber implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /home/vagrant/code/vendor/propaganistas/laravel-phone/src/PhoneNumber.php on line 22

PHP Deprecated: Return type of League\ISO3166\ISO3166::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/vendor/league/iso3166/src/ISO3166.php on line 111

PHP Deprecated: Return type of League\ISO3166\ISO3166::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/vendor/league/iso3166/src/ISO3166.php on line 123

I reproduced this error on two different servers running PHP 8.1 and a new Laravel project. I am getting the error when I try to use the validation rule in a form request. The package worked after I reverted to PHP 8.

  • laravel/framework v8.68.1
  • propaganistas/laravel-phone v4.3.2

PHP 8.1 compatibility is on the radar.

Hello. Is there an update on this @Propaganistas ? Thanks!

Can you pull in commit hash 90ea4906a67ecbfd6255f9f77806401a81e2d6ac and check if the warnings are resolved?
If so, I'll create a release.

Just pulled it in, but it's really weird. When running the app normally, no issues, however when I run Laravel Dusk tests, I still get

PHP Deprecated: Return type of Propaganistas\LaravelPhone\PhoneNumber::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/vendor/propaganistas/laravel-phone/src/PhoneNumber.php on line 375

I should emphasise that this seems to be occurring regardless of whether it is used on a particular page. I'm wondering if it is an autoload issue? I even configured composer.json to not auto-discover the service provider and still got the issue.

Weird, everything's in place... It seems Dusk is using a cached version because it's still referencing line 375 as the function's definition, while it's living on line 376 in the meantime.

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->formatE164();
}

Okay problem solved. Seems to have been Laravel Valet. Restarting it fixed the issue, so yeah, I think we can do a release now.

version 4.3.5