rector icon indicating copy to clipboard operation
rector copied to clipboard

System error: "Syntax error, unexpected T_NS_SEPARATOR:1"

Open frederic100 opened this issue 3 years ago • 9 comments

Hello,

I have got this error message (bin/php is a docker run on a php container, this is my firts experience with Rector. I joined the asked report in this message ) :

bin/php vendor/bin/rector process --clear-cache src/Infrastructure/Web/site/mod_turbolead/classes/openid/Auth/Yadis/ParseHTML.php 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

[ERROR] Could not process "src/Infrastructure/Web/site/mod_turbolead/classes/openid/Auth/Yadis/ParseHTML.php" file, due to: "System error: "Syntax error, unexpected T_NS_SEPARATOR:1" Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 269

Sincerly, Frédéric report.txt

frederic100 avatar Jul 24 '22 16:07 frederic100

Hi,

we'll need exact reproducer from your code. It will be most likely single line, an invalid syntax. You can make one here: https://getrector.org/demo

TomasVotruba avatar Jul 24 '22 16:07 TomasVotruba

https://getrector.org/demo/07418a2b-028f-4232-9068-d26c0eb742f5

frederic100 avatar Jul 24 '22 20:07 frederic100

Thanks. Could you narrow the input file to ~10 lines that cause the issue? Then we can identify the broken spot.

TomasVotruba avatar Jul 24 '22 20:07 TomasVotruba

I updated the demo link. (error come frome here: $str = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $str);

'chr(\1)' exactly )

frederic100 avatar Jul 25 '22 07:07 frederic100

Thanks! Could you share a new link to the code? The link is unique per code input, and the link above still contains the old code.

TomasVotruba avatar Jul 25 '22 07:07 TomasVotruba

it seems due to PregReplaceEModifierRector, ref https://getrector.org/demo/64cc5d5c-8980-4521-b38e-15c5556bb991

samsonasik avatar Jul 25 '22 10:07 samsonasik

Thanks! Could you share a new link to the code? The link is unique per code input, and the link above still contains the old code.

For sure. Here it is : https://getrector.org/demo/f361369c-058a-42df-b892-deb48f62a16e

frederic100 avatar Jul 25 '22 13:07 frederic100

That's seems due to no quote in chr(\1):

-chr(\\1)
+chr('\\1')

The following code will be transformed correctly:

$str = preg_replace('~&#([0-9]+);~e', "chr('\\1')", $str);

ref https://getrector.org/demo/73def251-e46e-4a39-b981-8c760d6aaafb

samsonasik avatar Jul 25 '22 13:07 samsonasik

Thank you. I don't know if we can close this issue because it has been solve for my case but I don't know if Rector could embed its correction.

frederic100 avatar Jul 26 '22 08:07 frederic100

I've merged the fix from https://github.com/rectorphp/rector-src/pull/2771

Thank you @samsonasik for the fix and @frederic100 for the test fixture :+1:

TomasVotruba avatar Aug 17 '22 09:08 TomasVotruba