PHP ParseError: Unclosed '{' in on line 1
gtsiou opened this issue · 4 comments
Pint Version
1.10.6
PHP Version
8.2.8
Description
This is a continuation of (and most likely the same issue as) #189
I can also confirm that the last version that did not had this issue, was 1.4.0
WSL on Windows 10
gtsiou@DESKTOP-OJ1FV27:~/projects/example-app$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
gtsiou@DESKTOP-OJ1FV27:~/projects/example-app$ php -v
PHP 8.2.8 (cli) (built: Jul 8 2023 07:09:59) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
Running something like ./vendor/bin/pint --test -v
in a new Laravel installation throws the following parsing error.
PHP 32. Illuminate\View\Compilers\BladeCompiler->hasEvenNumberOfParentheses($expression = '@if ($nonFixableErrors->isNotEmpty()') phar:///home/gtsiou/projects/example-app/vendor/laravel/pint/builds/pint/vendor/illuminate/view/Compilers/BladeCompiler.php:539
PHP 33. token_get_all($code = '<?php @if ($nonFixableErrors->isNotEmpty()') phar:///home/gtsiou/projects/example-app/vendor/laravel/pint/builds/pint/vendor/illuminate/view/Compilers/BladeCompiler.php:604
PHP ParseError: Unclosed '(' in on line 1
PHP Stack trace:
PHP 1. {main}() /home/gtsiou/projects/example-app/vendor/bin/pint:0
PHP 2. include() /home/gtsiou/projects/example-app/vendor/bin/pint:120
However, the command completes successfully and works as it should.
Looks like the token_get_all fails on <?php @if ($nonFixableErrors->isNotEmpty()'
This seems to be thrown by the code added here so maybe not a Pint issue, but definitely the suppression does not work as it should in this instance, so it could be related to the PHP configuration in my system which has the following settings regarding error handling:
gtsiou@DESKTOP-OJ1FV27:~/projects/example-app$ php --info | grep error
display_errors => Off => Off
display_startup_errors => Off => Off
error_append_string => no value => no value
error_log => no value => no value
error_log_mode => 0644 => 0644
error_prepend_string => no value => no value
error_reporting => 22527 => 22527
html_errors => Off => Off
ignore_repeated_errors => Off => Off
log_errors => On => On
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
opcache.error_log => no value => no value
Steps To Reproduce
-
Create a new Laravel project
composer create-project laravel/laravel example-app
-
Run pint in the project
cd example-app; ./vendor/bin/pint --test -v
After a little bit of Reviewing I think the problem lies with token_get_all
(though I can't reproduce it on macOS)
@gtsiou could you run the following command in WSL:
php -r "var_dump(token_get_all('<?php @if ($nonFixableErrors->isNotEmpty()'));"
Does this throw a ParseError or do you get an array back?
This is my Result on macOS
array(9) {
[0]=>
array(3) {
[0]=>
int(389)
[1]=>
string(6) "<?php "
[2]=>
int(1)
}
[1]=>
string(1) "@"
[2]=>
array(3) {
[0]=>
int(287)
[1]=>
string(2) "if"
[2]=>
int(1)
}
[3]=>
array(3) {
[0]=>
int(392)
[1]=>
string(1) " "
[2]=>
int(1)
}
[4]=>
string(1) "("
[5]=>
array(3) {
[0]=>
int(384)
[1]=>
string(2) "->"
[2]=>
int(1)
}
[6]=>
array(3) {
[0]=>
int(262)
[1]=>
string(10) "isNotEmpty"
[2]=>
int(1)
}
[7]=>
string(1) "("
[8]=>
string(1) ")"
}
Good catch @Jubeki!
You should escape the '$' character in the example you sent, since your CLI thinks it is a variable but I think even then it will work for you (php -r "var_dump(token_get_all('<?php @if (\$nonFixableErrors->isNotEmpty()'));"
)
I do indeed get an error:
Result on WSL, PHP 8.2.8
``` PHP ParseError: Unclosed '(' in on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 PHP 2. token_get_all($code = 'isNotEmpty()') Command line code:1 Command line code:1: array(10) { [0] => array(3) { [0] => int(389) [1] => string(6) " int(1) } [1] => string(1) "@" [2] => array(3) { [0] => int(287) [1] => string(2) "if" [2] => int(1) } [3] => array(3) { [0] => int(392) [1] => string(1) " " [2] => int(1) } [4] => string(1) "(" [5] => array(3) { [0] => int(266) [1] => string(17) "$nonFixableErrors" [2] => int(1) } [6] => array(3) { [0] => int(384) [1] => string(2) "->" [2] => int(1) } [7] => array(3) { [0] => int(262) [1] => string(10) "isNotEmpty" [2] => int(1) } [8] => string(1) "(" [9] => string(1) ")" } ```I think it would be best to report this to PHP directly then, as Pint can not change this behaviour.
Closing as the issue seems to be irrelevant to this repo.