Insane Insane - 1 year ago 121
PHP Question

PHP PSR-4 - Class not found

I've added my namespace with PHP, but can't get it working.

What I am doing wrong with my setup? When I want to call my test-class:

I get the error message:

Class 'KWinkel\Helpdesk\Controller\TanoaLife' not found

My setup:


ini_set('display_errors', '1');

// autoloader
$Autoloader = require __DIR__ . '/vendor/autoload.php';
$Autoloader->add('KWinkel\\Helpdesk\\', 'app/');

// controller
if ( isset($_GET["controller"]) ) {
$Controller = $_GET["controller"];
if ( file_exists("app/Controller/" . $Controller . ".class.php") ) {
$Class = "KWinkel\Helpdesk\Controller\\" . $Controller;
new $Class($_GET["params"]);
} else {
echo "invalid call #1";
} else {
echo "invalid call #2";

$SysContent = ob_get_contents();
echo $SysContent;


namespace KWinkel\Helpdesk\Controller;

class TanoaLife extends AbstractController {

function __construct ($Params) {
echo "params: " . $Params;



Answer Source

Your classfile TanoaLife.class.php should look like this:

 namespace KWinkel\Helpdesk\Controller;

 class TanoaLife {


and should be placed here:


to work with the Autoloader.

UPDATE: I would prefer to name the classfile TanoaLife.php instead of TanoaLife.class.php or you have to setup the autoloader to include classes with suffix .class.php

$Autoloader->addPsr4('KWinkel\\Helpdesk\\', 'app');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download