I dont want to use the namespace keyword in each class
If you don't want use namespace, then don't use it. If your problem is only to use an autoloader then you can simply map each class with its directory path.
$srcDir = __DIR__. '/src';
$formDir = $srcDir . '/HTML/Form';
$classesMap = array(
'Db' => $srcDir . '/Setting/Db.php',
'Form' => $formDir . '/Form.php',
);
This work would not be necessary if you followed one standard like PSR-0/4 or the (old) PEAR coding standard.
If you're using composer, look classmap.
is there a way to load a class into a namespace?
Something like
function autoload($class) {
namespace DynamicNamespace {
require ('/path/to/classes/'. $class);
};
}
is not allowed.