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

1.2.6: $dispatcher->getControllerName() not returning a string?

The situation: I have two environments: my local dev machine (Dev), and my production server with Media Temple (Prod). I've installed Phalcon on both. Dev seems to be successfully running a very basic (1 controller) Phalcon site. However, Prod is having issues with the same code.

The problem: I'm trying to convert non-camelcased controllers and actions to valid camelcased ones (e.g. "test-page" to "testPage"). This is working on Dev but not Prod. The error I'm receiving on Prod is: php Warning: Invalid arguments supplied for camelize()

Using the following code:

$eventsManager->attach('dispatch', function ($event, $dispatcher) {
      $controllerName = Phalcon\Text::camelize($dispatcher->getControllerName()); // Throwing an error here...
      $dispatcher->setControllerName($controllerName);

      $actionName = Phalcon\Text::camelize($dispatcher->getActionName()); // ... and here
      $dispatcher->setActionName($actionName);
});

Looking at https://github.com/phalcon/cphalcon/blob/master/ext/kernel/string.c#L225 it looks like the camelize() function returns this error when the value is not a string.

The question(s): So this would mean that $dispatcher->getControllerName() is not returning a string?

Why would this be happening? What would cause this function return different types?

I can't test right now, but use var_dump($dispatcher->getControllerName()) to know the type.

If it's not a string (it's really weird) use

$controllerName = (string) $dispatcher->getControllerName();

Casting to (string) makes the error go away, but then no controller gets loaded. It just renders the default layout with no other content.

I made a gist, maybe it will help: https://gist.github.com/ryanwalters/9002906