We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

'Phalcon\Annotations\Exception' with message 'Scanning error before 'ExitExpression) ..

I have tried all kinds of ways but it just doesn't work.

I want to use annotations but no matter what I put in the doc block, it gives the error: Scanning error before 'ExitExpression

And I have tried php5.5 and php5.6, phalcon 1.3.3 and phalcon 1.3.4. It just doesn't work.

Actually, I used php5.5.12 and phalcon1.3.3 and annotations a couple months ago. But it just doesn't work with all the environment the same.

The following is the backstrace:

Fatal error: Uncaught exception 'Phalcon\Annotations\Exception' with message 'Scanning error before 'ExitExpression) ...' in /vagrant/data/code/phalcon/app/controllers/ErrorController.php on line 7' in /vagrant/data/code/phalcon/app/plugins/VerifyParamsPlugin.php:11 Stack trace: #0 [internal function]: Phalcon\Annotations\Reader->parse('Live\Controller...') #1 [internal function]: Phalcon\Annotations\Adapter->get(Object(Live\Controllers\ErrorController)) #2 /vagrant/data/code/phalcon/app/plugins/VerifyParamsPlugin.php(11): Phalcon\Annotations\Adapter->getMethod(Object(Live\Controllers\ErrorController), 'notFoundAction') #3 [internal function]: Live\Plugins\VerifyParamsPlugin->beforeExecuteRoute(Object(Phalcon\Events\Event), Object(Phalcon\Mvc\Dispatcher), NULL) #4 [internal function]: Phalcon\Events\Manager->fireQueue(Array, Object(Phalcon\Events\Event)) #5 [internal function]: Phalcon\Events\Manager->fire('dispatch:before...', Object(Phalcon\Mvc\Dispatcher)) #6 [internal function]: Phalcon\Dispatcher->dispatch() #7 /vag in /vagrant/data/code/phalcon/app/plugins/VerifyParamsPlugin.php on line 11

Could you please post the comment of ErrorController.php line 7?



3.4k
edited Apr '15
<?php
namespace Live\Controllers;

use Live\Library\Exception;

class ErrorController extends AbstractController
{ // line 7
    public function notFoundAction()
    {
        throw new Exception('10003');
    }
}

Actually, no matter what the content is, it tells there is an error on line 7.

Could you please post the comment of ErrorController.php line 7?

Are you using opcache or similar?



3.4k
Accepted
answer
edited Apr '15

No. Finally I found the error. There is an error in AbstractController, but the error message tells it is the ErrorController.

    /**
     * @SuppressWarnings(PHPMD.ExitExpression) 
     */
    protected function renderJson(array $data, $statusCode = 200)
    {
        $this->response->setContentType('application/json', 'UTF-8');
        $this->response->setStatusCode($statusCode, self::$httpStatusCodeAndMessages[$statusCode]);
        $this->response->setJsonContent($data, JSON_UNESCAPED_SLASHES);
        $this->response->send();
        exit;
    }

The annotation I put is to avoid PHPMD warning, but conflicts with phalcon's annotation.

So can this be improved?

Are you using opcache or similar?

Has anyone found a way to prevent the annotations parser parsing PHPMD rules? It tries to parse them even though I haven't asked it to throwing the same exception you had...