PHP class not found in autoloaded implementation file

836 views Asked by At

I really hope this isn't a duplicate, but here I go:

I use Zend's autoloader to load classes. It seems to work, at least it loads the correct file when instantiating my class (Common_TestTest) which is implemented in Common/TestTest.php. But then I get the following error message:

"Class Common_TestTest could not be found in Common/TestTest.php."

There's nothing in TestTest.php other than the class:

<?php

class Common_TestTest extends PHPUnit_Framework_TestCase
{
    public function testTesting() {
        $this->assertTrue(true);
        $this->assertFalse(true);
    }
}

I tried dumping get_declared_classes at the end of the file, everything looks fine, Common_TestTest is one of the declared classes - but the exception is still thrown when leaving the file.

The funniest bit is: When I change the name of the class from Common_TestTest to TestTest the same things happens - only that the error message states the name of the missing class as "TestTest". So it definitely sees the class and reacts to it's presence.

1

There are 1 answers

0
dbrumann On

There are 2 possibilities that come to my mind as to what causes the problem:

  1. You have some case-mismatch between class-name and file-name, e.g. Testtest.php

  2. When registering the Namespace you use "Common" instead of "Common_". Zend_Loader_Autoloader does not distinguish between PHP 5.3 style namespaces and ZF-style namespaces (rather Prefix). By appending the underscore you make sure, that your namespace is interpreted as a class-prefix rather than a real namespace.