I'm having trouble with calling a class within the same namespace dynamically.
To simplify my system:
I have this namespace structure:
core
core\classes
In core\classes there are two classes (in two files, both were included before):
class AUTO_LOAD
{
public function regSingleton($event)
{
$temp_event = $event;
//$event = '_' . $event;
//global $$event;
//$$event = $temp_event::newInst(); // the old version without namespaces - this worked
HELPER::varDump(SYSTEM::newInst()); // this works
HELPER::varDump($temp_event::newInst()); // this doesn't work
exit;
}
}
and
class SYSTEM
{
// Some code;
}
Then instantiate AUTO_LOAD:
$_AUTO_LOAD = new AUTO_LOAD;
$_AUTO_LOAD->regSingleton('SYSTEM');
Output:
object(core\classes\SYSTEM)#2 (3) {}
Fatal error: Class 'SYSTEM' not found in .../system/includes/classes/class.autoload.php
As you can see above if I try to call SYSTEM::newInst() (statically) it works, but if I try to run it dynamically ($temp_event::newInst()) it doesn't.
Neither a direct call via '\\' . __NAMESPACE__ . '\\' . $temp_event::newInst(); nor via '\\core\classes\\' . $temp_event::newInst(); works (same output).
Where is the error (in reasoning)? Thanks for any help in advance!
PS: I already read PHP namespace with Dynamic class name but I can't see the difference?