After 4 years of absence in PHP programming I’m trying to make some new project in it.
I’m collecting some useful libraries. And I have problem with “use” keyword. Here is my part of code where error is thrown.
<?PHP
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
$js = new AssetCollection(array(
...
?>
And I’m getting error:
Fatal error: Class 'Assetic\Asset\AssetCollection' not found in /home/php/index.php on line 7
I thought that is maybe something wrong with include_path in php.ini, but it looks like that:
include_path = ".:/usr/share/php5:/usr/share/php"
Did I miss something?
BTW. I’m using nginx + php-fpm.
The use keyword does not actually include any files. I’m afraid you either have to register an autoload function with the spl_register_autoload() call, or manually include the files.
http://www.php.net/manual/en/function.spl-autoload-register.php
Usually a good default autoloader will look for files following the same path as the namespaces, like this:
More on autloading in PHP, a structure that many (newer) projects are following: http://groups.google.com/group/php-standards/web/psr-0-final-proposal