By doing so, it is possible to keep the namespace restriction, while avoiding harcoded strings as class name. Furthermore, IDEs like PHPStorm can now jump to the specified class, using the corresponding shortcuts.
Usage
Basically, the usage does not differ much, only the namespace needs to be provided. This means that either MyModel::class or "\Namespace\To\MyModel" can be used instead of "MyModel" only.
While the latter seems to be of disadvantage as it requires additional information passed by the user, the former is the intended way to go. Not only because of the aforementioned reasons, but also because the code has increased readability and maintainability.
Why change?
By doing so, it is possible to keep the namespace restriction, while avoiding harcoded strings as class name. Furthermore, IDEs like PHPStorm can now jump to the specified class, using the corresponding shortcuts.
Usage
Basically, the usage does not differ much, only the namespace needs to be provided. This means that either
MyModel::class
or"\Namespace\To\MyModel"
can be used instead of"MyModel"
only. While the latter seems to be of disadvantage as it requires additional information passed by the user, the former is the intended way to go. Not only because of the aforementioned reasons, but also because the code has increased readability and maintainability.Additional Information
A proper exception was added to notify the programmer about invalid classes in use.