Aliases in a lazy class?

The class_alias function seems to immediately load the class into memory when the statement is executed, and not the first time the class is actually used. Is it possible / recommended to install some kind of lazy loading mechanism for class aliases?

For example, it is possible to store aliases in an array, and in the __autoload function, check this array and define an alias when the class is actually used.

+4
source share
1 answer

The simple answer is to not use this function for alias classes, but to use the use construct:

 <?php namespace foo\bar; use \some\other\class\name as name; $foo = new name(); 

It will be lazily loaded.

+3
source

All Articles