phroute
phroute copied to clipboard
Deprecation in PHP 8.4 (Solution)
@mrjgreen
I have been using PHP 8.1 - 8.3 without any problems using Phroute, but I have upgraded to PHP 8.4 and it throws several deprecation errors when I run my project tests.
1) /var/www/html/vendor/phroute/phroute/src/Phroute/RouteCollector.php:57
Phroute\Phroute\RouteCollector::__construct(): Implicitly marking parameter $routeParser as nullable is deprecated, the explicit nullable type must be used instead
1) /var/www/html/vendor/phroute/phroute/src/Phroute/RouteCollector.php:74
Phroute\Phroute\RouteCollector::route(): Implicitly marking parameter $args as nullable is deprecated, the explicit nullable type must be used instead
Deprecated: Phroute\Phroute\Dispatcher::__construct(): Implicitly marking parameter $resolver as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/src/Phroute/Dispatcher.php on line 20
It was originally built this way.
// class: Phroute\Phroute\RouteCollector::class
public function __construct(RouteParser $routeParser = null) {}
public function route($name, array $args = null) {}
// class: Phroute\Phroute\Dispatcher::class
public function __construct(RouteDataInterface $data, HandlerResolverInterface $resolver = null) {}
A possible fix with data typing. I have run the tests with those fixes adding a '?' to the data typing, this seems to fix the current issues.
// class: Phroute\Phroute\RouteCollector::class
public function __construct(?RouteParser $routeParser = null) {}
public function route($name, ?array $args = null) {}
// class: Phroute\Phroute\Dispatcher::class
public function __construct(RouteDataInterface $data, ?HandlerResolverInterface $resolver = null) {}
Tests run with Phroute installed.
PHP 8.4.1 (cli) (built: Nov 21 2024 18:18:09) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.1, Copyright (c) Zend Technologies
with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans
PHPUnit 11.4.4 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.1
Configuration: /var/www/html/phpunit.xml
........................................................ 56 / 56 (100%)
Time: 00:00.862, Memory: 12.00 MB
OK (56 tests, 164 assertions)
Development environment.
Debian 12 Bookworm
Docker compose lts
image: php:8.4-apache