[TYPO3-core] CGL and "use" statement

Stefan Neufeind typo3.neufeind at speedpartner.de
Fri Dec 14 16:07:49 CET 2012

On 12/14/2012 02:42 PM, Sebastian Michaelsen wrote:
> 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.



in case of too generic class names you could use an alias.
(use ... as ...).
We need to make sure though to use meaningful aliases then and maybe
reuse common aliases in various places. Maybe alias-usage could be
"reserved" for special cases only and we'll have a central list of
exceptions where the agree to use aliases - so that not not somebody
uses "Util" and the other "GU" for the GeneralUtility (not that it would
need an alias, just an example).


More information about the TYPO3-team-core mailing list