I’ve been very busy lately, for example with the first release of Mai Ocean, that it was hard to find time for writing posts.
Of course I had to give some sign of life! Therefore I am filling this first post of the year with a great function I recently found.
When writing the handler system for Mai Ocean I had to find a way to access a static class that had a variable name. Accidentally I found the new class_alias() function on php.net. This function gives you the ability to easily create a alias for any class. Usage is simple:
class_alias('New', 'Original');
The function is available in version 5.3 and above and works with namespaces. In Mai Ocean I just use the following:
$handler = 'MaiOcean\UserHandler\\' . $this->config()->handlers->name; class_alias($handler, 'MaiOcean\UserHandler\Handler');
Now I can just use my new name instead of a variable! How great is that?





