0

Whenever I am trying to clear the cache on Symfony2 I am constantly getting the following error:

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

Here's what line 177 looks like:

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

Any idea why this is? This just happened after I upgrade my Lion OS X, before it works just fine with the code above.

13
  • What version of PHP are you running? Greater than or equal to 5.3? Commented Nov 23, 2013 at 4:42
  • @DavidEugenePeterson I am running PHP 5.3.26 (cli) (built: Jul 7 2013 19:05:08) Commented Nov 23, 2013 at 4:43
  • Set $dateRange = [] to $dateRange = NULL then clear cache manually in the app/cache directory. Can you execute the app/console router:debug command afterwards without error? Commented Nov 23, 2013 at 4:49
  • @DavidEugenePeterson actually I am running PHP Version 5.4.13. And yes after changing to $dateRange = NULL the error goes to the next line that has the [] issue. I can't use [] in 5.4? Commented Nov 23, 2013 at 4:57
  • 1
    I'm confused there's only one line in the code you provide that uses the short array syntax []. Which line, exactly, is line 177? You have 7 lines of code there. Commented Nov 23, 2013 at 5:01

1 Answer 1

2

The method's default argument $dateRange = [] uses the short array syntax that was introduced in PHP 5.4.

Your PHP command line interface uses PHP 5.3 that can't understand this syntax.

Therefore the method declaration results in a PHP Parse error.

Change the method to ...

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

... to resolve the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.