$ php -v):=> PHP 7.0.22
$ php-cs-fixer -V):=> PHP CS Fixer 2.9.0
=> vendor/bin/php-cs-fixer fix --config=.php_cs.dist
[
'explicit_string_variable' => true
]
$query = "select id from $tableName where deleted_at is null";
$query = "select id from ${tableName} where deleted_at is null";
$query = "select id from {$tableName} where deleted_at is null";
I don't find information on php documentation about this, but I found a lot of examples on this way: {$var}
echo "El usuario $user->first_name no existe."
echo "El usuario ${user}->first_name no existe."
echo "El usuario {$user->first_name} no existe."
The last example, I think is very complicated, but if we can do somenthing, great! If not, a simple warning would be enough.
Thanks @pablorsk for reporting,
@Slamdunk , as author of the fixer, may I ask for your thoughts on this?
Fixed in #3334 released in 2.9.1
@pablorsk please try again after updating to 2.9.1
thanks @Slamdunk :+1:
@SpacePossum
I'm sorry,I try with v2.10.0
$query = "select id from $tableName";
$query = "select id from ${tableName}";
$query = "select id from {$tableName}";
$user->first_name
works perfect!
{$user->first_name}
thanks for reporting back @alexisverardo
closing this issue as reported that it has been fixed :)
Sorry @SpacePossum but,
From
$query = "select id from $tableName";
to
$query = "select id from ${tableName}";
It's correct? Is not correct this?
$query = "select id from {$tableName}";
Maybe we are wrong. Do you have official documentation? I don't found anything for this case on php.net
all 3 forms have same value. all of them are correct.
fixer simply change initial form to other, that we think is better
@alexisverardo @pablorsk yes it is the expected behaviour, try to run:
$ php-cs-fixer describe explicit_string_variable
To have the related documentation.
For simple variable, ${var} is preferred over {$var} because the former it is considered the simple syntax, while the latter the complex one.
See the official documentation: https://secure.php.net/manual/en/language.types.string.php#language.types.string.parsing
Simple rules are preferred over complex ones.
Closing as there is nothing left to do here I think? Please comment if you think there is and we can reopen.
Most helpful comment
@alexisverardo @pablorsk yes it is the expected behaviour, try to run:
To have the related documentation.
For simple variable,
${var}is preferred over{$var}because the former it is considered the simple syntax, while the latter the complex one.See the official documentation: https://secure.php.net/manual/en/language.types.string.php#language.types.string.parsing
Simple rules are preferred over complex ones.