Symfony2调用应用程序/控制台缓存时PHP分析错误:清除


Symfony2 PHP Parse error when invoking app/console cache:clear

每当我试图清除Symfony2上的缓存时,我总是会收到以下错误:

PHP Parse error:  parse error in /Users/Adam/Sites/MyApp/src/MyApp/MainBundle/Services/TransactionManager.php on line 177
PHP Stack trace:
PHP   1. {main}() /Users/Adam/Sites/MyApp/app/console:0
PHP   2. Symfony'Component'Console'Application->run() /Users/Adam/Sites/MyApp/app/console:32
PHP   3. Symfony'Bundle'FrameworkBundle'Console'Application->doRun() /Users/Adam/Sites/MyApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
PHP   4. Symfony'Component'HttpKernel'Kernel->boot() /Users/Adam/Sites/MyApp/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70
PHP   5. Symfony'Component'HttpKernel'Kernel->initializeContainer() /Users/Adam/Sites/MyApp/app/bootstrap.php.cache:2215
PHP   6. Symfony'Component'DependencyInjection'ContainerBuilder->compile() /Users/Adam/Sites/MyApp/app/bootstrap.php.cache:2435
PHP   7. Symfony'Component'DependencyInjection'Compiler'Compiler->compile() /Users/Adam/Sites/MyApp/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:629
PHP   8. JMS'AopBundle'DependencyInjection'Compiler'PointcutMatchingPass->process() /Users/Adam/Sites/MyApp/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:119
PHP   9. JMS'AopBundle'DependencyInjection'Compiler'PointcutMatchingPass->processDefinition() /Users/Adam/Sites/MyApp/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:59
PHP  10. class_exists() /Users/Adam/Sites/MyApp/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:96
PHP  11. Composer'Autoload'ClassLoader->loadClass() /Users/Adam/Sites/MyApp/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:0

以下是第177行的样子:

/**
 * {@inheritDoc} 
 */
public function findAwaitingPaymentTransactionsByUserId( $dateRange = [] )
 {
   // ...
 }

知道为什么吗?这只是在我升级Lion OS X之后发生的,在它与上面的代码配合使用之前。

方法的默认参数$dateRange = []使用PHP 5.4中引入的短数组语法

您的PHP命令行界面使用的PHP 5.3无法理解此语法。

因此,方法声明会产生一个PHP Parse error

将方法更改为。。。

// array() instead of []
public function findAwaitingPaymentTransactionsByUserId( $dateRange = array() )
{
    // ...
}

以解决问题。