Skip to content

[BUG] Fatal error: During class fetch / Missing Warnings #2435

@Fenikkusu

Description

@Fenikkusu

use Statements are not getting checked for existence during the Generation step. This can create issues where you will get a fatal error During class fetch. I noticed this specifically when working with error exceptions.

namespace My\Stuff;

use Throwable;
use Phalcon\Views\Exception as ViewException // Note the misspelling
use Phalcon\Di\Injectable;
use Phalcon\Events\EventInterface;
use Phalcon\Dispatcher\DispatcherInterface;

class Listener extends Injectable
{
    public function beforeException(<EventInterface> event, <DispatcherInterface> dispatcher, <Throwable> exception)
    {
        try {
            throw exception;
        } catch ViewException {
            throw new \Exception("Reached");
        } catch Error {
           // Never Reached
        }
    }
}

In the psudo code above, I am referencing the wrong path for the exception (note the extra 's'). When the throw occurs in the beforeException method, it will cause the fatal error During class fetch with no other details. Normally I would not bother creating an issue for this, except that I have no warnings in the Generate step indicating that the Class doesn't exist at compile time. It took me the better part of several hours to understand what was the issue and a lot of commenting out of code sections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions