phpfuelphp

"Cannot redeclare class" issue in FuelPHP


Working namespaces in a default FuelPHP installation I add the following to the welcome controller (otherwise unedited) and I start getting the error:

ErrorException [ Compile Error ]: Cannot redeclare class Fuel\Controller\Welcome"

The code I is:

<?php

namespace Fuel\Controller;

use Fuel\Core\Controller;


class Welcome extends Controller
{
...
}

This is probably a beginner's question but I just can't figure out why the collision is occurring and I have tried everything I can think of.

EDIT: I even tried putting the following code in front of the class and the error disappeared but a very generic looking 404 page was displayed. (Not the one that is displayed by default with FuelPHP but a black/grey one)

if (class_exists("Controller\Welcome",false)) {
//    echo "here. (" . __FILE__ . ":" . __LINE__ . ")\n";

} else {
    //Class definition...

}

Solution

  • The answer turned out to be that you have to change the controller prefix in the config file to the following:

      'controller_prefix' => 'Controller\\',
    

    Which is actually written in the documentation. (silly me)