I'm currently working on some project on Symfony 2.8. I've come across this weird PHP error.
I'm building a symfony command that allows using Kahlan test framework inside a Symfony project. Thus, I need the Symfony container to be available in Kahlan test suites, and so to be defined as global variable of said suites. Simple matter with the Container aware command.
But here comes the glitch. When I try to call a service that uses Symfony's security.authorization_checker
service, the cli returns this error:
PHP Parse error: syntax error, unexpected ',' in /tmp/kahlan/data/www/project/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguageProvider.php on line 55
The code of said file:
[...]
public function getFunctions()
{
return array(
new ExpressionFunction('is_anonymous', function () {
return '$trust_resolver->isAnonymous($token)';
}, function (array $variables) {
return $variables['trust_resolver']->isAnonymous($variables['token']);
}),
new ExpressionFunction('is_authenticated', function () {
return '$token && !$trust_resolver->isAnonymous($token)';
}, function (array $variables) {
return $variables['token'] && !$variables['trust_resolver']->isAnonymous($variables['token']);
}),
new ExpressionFunction('is_fully_authenticated', function () {
return '$trust_resolver->isFullFledged($token)';
}, function (array $variables) {
return $variables['trust_resolver']->isFullFledged($variables['token']);
}),
new ExpressionFunction('is_remember_me', function () {
return '$trust_resolver->isRememberMe($token)';
}, function (array $variables) {
return $variables['trust_resolver']->isRememberMe($variables['token']);
}),
new ExpressionFunction('has_role', function ($role) {
return sprintf('in_array(%s, $roles)', $role);
}, function (array $variables, $role) {
return in_array($role, $variables['roles']);
}),
);
}
[...]
Line 55 is the line of the last array element, thus said comma is the trailing comma. The error is thrown only in cli. An of course, I have tried removing the comma, everything works then perfectly. But obviously, I can't change Symfony's built-in classes.
So, How come PHP throws Parse Errors for a trailing comma in an array only in cli mode, and do you guys have any idea on how to fix this?
Thanks.