-
-
Notifications
You must be signed in to change notification settings - Fork 234
Description
Description
When running PHP 8.4 with the latest Symfony components (v7.x or v8.x, e.g., in Laravel 12), symfony/panther (v2.3.0 and dev-main) throws Fatal Errors immediately upon usage.
This is due to strict type enforcement in PHP 8.4 combined with the updated method signatures in the upstream Symfony\Component\BrowserKit\AbstractBrowser and Symfony\Component\DomCrawler\Crawler.
Steps to Reproduce
Install symfony/panther (v2.3.0)
Run on PHP 8.4 environment.
Ensure symfony/browser-kit and symfony/dom-crawler are at version ^7.0 or ^8.0.
Attempt to initialize the Client.
Error 1: Client.php
Exception:
code Text
Symfony\Component\ErrorHandler\Error\FatalError: Declaration of Symfony\Component\Panther\Client::doRequest($request) must be compatible with Symfony\Component\BrowserKit\AbstractBrowser::doRequest(object $request): object
Location: src/Client.php:294
Error 2: Crawler.php (occurs after fixing Error 1)
Exception:
code Text
Symfony\Component\ErrorHandler\Error\FatalError: Declaration of Symfony\Component\Panther\DomCrawler\Crawler::closest(string $selector): ?Symfony\Component\Panther\DomCrawler\Crawler must be compatible with Symfony\Component\DomCrawler\Crawler::closest(string $selector): ?static
Location: src/DomCrawler/Crawler.php:145
Proposed Fixes
To fix compatibility with the latest Symfony contracts and PHP 8.4, the method signatures need to be updated.
- Fix src/Client.php
The doRequest method needs the return type hint : object.
code Diff
- protected function doRequest($request)
- protected function doRequest(object $request): object
{
// ...
}
- Fix src/DomCrawler/Crawler.php
The closest method needs to return ?static instead of the specific class name to satisfy the parent class signature.
code Diff
- public function closest(string $selector): ?Crawler
- public function closest(string $selector): ?static
{
// ...
}
Environment
PHP: 8.4.12
Panther: v2.3.0 / dev-main
Symfony Components: ^7.0 / ^8.0 (Laravel 12 context)