I have a directory include. In this directory, I have only one dir: HQF. In this directory, I have many files where I always declare them belonging to the HQF namespace like this:
<?php
namespace HQF;
class MyClass
{
}
And the file is called "MyClass.php". I'm trying to stick "a bit" to PSR0.
Everything works fine, and I've made my autoloader like this:
function __autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DS, $namespace).DS;
}
$fileName .= str_replace('_', DS, $className).'.php';
$fileName = 'include/'.$fileName;
require $fileName;
}
So when I need a class I just have to do: $m = new \HQF\MyClass(); and it works like a charm, including automagically the file "include/HQF/MyClass.php"
I have a problem with "pure" functions.
I've made a file called "include/HQF/mb_utils.php" where I want to put my mb_xxx function. NB: no classes, only functions.
I've tried all the following things without success:
$test=\HQF\mb_ucname('calling HQF/mb_ucname...');$test=\mb_ucname('calling HQF/mb_ucname...');use \HQF\mb_utils; and then the two tests above;
None of them work. What am I missing?