dependency-injectionphalconredeclare

Cannot redeclare class. Phalcon di


When I use require_once or include_once, it means that when I set a class to the phalcon di, it says cannot redeclare class PasswordDb. I don't want to put the class inside an if statement like

if(class_exists('ClassName') != true)

Is there a better way of doing this?

Phalcon di config is like this

$di->set('passwordDb', array(
    'className' => 'AS\Login\PasswordDb'
));

$di->set('passwordService', array(
    'className' => 'AS\Login\PasswordService',
    'arguments' => array(
        array('type' => 'service', 'name' => 'passwordDb')
    )
));

Solution

  • So it turned out to be a namespace error. The service had the wrong namespace. The error message wasn't exactly what I would have expected from such an error.

    Hopefully this will help someone in future.