[TYPO3-core] CGL and "use" statement
Sebastian Michaelsen
sebastian.michaelsen at t3seo.de
Fri Dec 14 14:42:51 CET 2012
hi everyone,
introducing php namespaces in TYPO3 6.0 was a great achivement. Working
with them for a bit now I was asking myself if the "use" statement would
be a good thing for our code.
What it is:
===========
It creates a Shortcut for a classname to that you don't need to write
down the full namespace path:
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
FlashMessageQueue::addMessage(new FlashMessage('flash!'));
Benefits:
=========
If you have good and speaking class names, this improves readability a low
Drawbacks:
==========
If you have too generic class names which you can't understand without
the according namespace, readability will decrease
I think we should decide on this and adopt the decision in our CGL.
I personally think that certain heavily used classes like
- GeneralUtility (former t3lib_div)
- FlashMessage and FlashMessageQueue
- BackendUtility
should be aliased with "use" if they occur a lot in a file. (e.g.
\TYPO3\CMS\Core\Utility\GeneralUtility occurs 145x in DataHandler)
More information about the TYPO3-team-core
mailing list