FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 704 forks source link

Problem with 2.x on PHP 7.x #2284

Closed kevinpapst closed 3 years ago

kevinpapst commented 3 years ago

Hi @GuilhemN ,

your fix for PHP 8 in the ClassUtils tokenizer here: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/d60e0ba3cc1f3dce11cedf65d8535cb17c506bd3/Routing/Loader/ClassUtils.php#L27-L31 seems to work in a standalone project.

The problem with this check is, that some libraries define this constant in user land code, see phpDocumentor and swagger-php for example (these two are used in a project of mine). And with this constant defined in user land code, the tokenizer breaks and the first namespace token is always true, resulting in a broken namespace 1\\MyController (see this CI run for example).

At least the Swagger bundle is likely be used in other projects that also use the Rest bundle.

Now we could argue that the 2.x branch is kind of deprecated and that defining this constant in user land code is the real problem, BUT other libraries fix the problem in another way (a quick google searched brought up this Drupal code

Instead of using if (defined('T_NAME_QUALIFIED')) { we could simply use if (PHP_VERSION_ID >= 80000) {.

Would you accept a PR for this? I already added one for the handcrafterinthealps routing bundle to support users of the 3.x branch.

GuilhemN commented 3 years ago

Indeed that would be definitively be safer. A PR for this would be great :)

Clanver commented 3 years ago

Can confirm this issue. We, as well, use swagger (in nelmioApiDocBundle) and it breaks the namespaces. Had to go back to 2.8.3 to fix this.

kevinpapst commented 3 years ago

Fixed by #2285 and released in https://github.com/FriendsOfSymfony/FOSRestBundle/releases/tag/2.8.5