php class not found while in (zend-based) include_path
===

<!-- language-all: lang-php -->

I have a class which is in a subdirectory of my library-folder in a zend-project. So lets say my app is in /Library/WebServer/Foo/, then php's include path is:

    <?php echo get_include_path(); ?>
    /Library/WebServer/Foo/application/../library:/Library/WebServer/Foo/library:/usr/share/zend-framework/library/

So now I want to create this class, ignore the random logic, and I should be able to reach it by just saying "new MyValidator_Usernameunique()" or something like that:

/Library/WebServer/Foo/library/MyValidator/Usernameunique.php

	<?php
	
	class MyValidator_Usernameunique extends Zend_Validate_Abstract
	{
		const USERNAME_ALREADY_EXISTS = 'usernameAlreadyUsed';
		const DATABASE_FAILED = 'userDatabaseFailure';
	 
		protected $_messageTemplates = array(
			self::USERNAME_ALREADY_EXISTS => "De gebruikersnaam '%value%' is al in gebruik, gebruik een andere."
			self::DATABASE_FAILED => "Er ging iets mis bij het verbinden met de database."
		);
	 
		public function isValid($value)
		{
			$magic = rand(0,3)
			if($magic==0) {
				$this->_error(self::USERNAME_ALREADY_EXISTS);
				return false;
			}
			if($magic==1) {
				$this->_error(self::DATABASE_FAILED);
				return false;
			}
			return true;
		}
	}

So I did exactly that:

/Library/WebServer/Foo/library/Form/Register.php

	<?php
	
	
	class Form_Register extends Form_FooForm {
	
		public function __construct() {
			parent::__construct();
			
			$username = $this->createText('username', 'Gebruikersnaam')->setRequired(true);
			$username->addValidator(new MyValidator_Usernameunique());
			//[Wed Jul 11 14:07:41 2012] [error] [client 127.0.0.1] PHP Fatal error:  Class 'MyValidator_Usernameunique' not found in /Library/WebServer/Foo/library/Form/Register.php on line 14, referer: http://foo/
		}
	}

Unfortunately, as I included in the piece of source, this rule errors "PHP Fatal error:  Class 'MyValidator_Usernameunique' not found in /Library/WebServer/Foo/library/Form/Register.php on line 14", ignore the line number as I simplified the code a bit.

Of course, this comes natural as /Library/WebServer/Foo/library/MyValidator/ is not in my php include_path and I did not 'require' or 'include' or 'require_once' the file. Yet, as I understand, zend is supposed to autoload the file by replacing the _ with / and searching the include_path. And this seems to work fine for the register-form, but fails for the validator. Now, why is this? It is almost the same scenario. Moreover, it also fails when I try to create a MyValidator_Usernameunique directly in a controller-class with the same error-message.

Any thought or indication on why this happens is well appreciated. Moreover, please note, I I am not trying to fix this error, I am trying to better understand autoloading in zend. So please do not propose solutions which make the use my validator redundant.