[TYPO3-core] Wrapper methods around globals?

Sebastian Fischer typo3 at evoweb.de
Fri Mar 21 14:24:35 CET 2014


For only local needs i dislike this approache.

What worked for me was, to define a local variable like:


/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
$database = $GLOBALS['TYPO3_DB'];

By this phpstorm knows what to deal with and autocompleten and syntax 
highlighting work as expected.

Greetings
Sebastian


Am 21.03.2014 14:19, schrieb Stephan Schuler:
> Hey there.
>
>
> If it's only about IDEs to not use globals and if it's about performance to not wrap them in pure getter functions: Why not make them a public static property of their original class?
>
> \TYPO3\CMS\Core\Database\DatabaseConnection::$databaseConnection = $GLOBALS['TYPO3_DB'];
>
> Of course that's an issue for whoever creates the TYPO3_DB object. Not every call of DatabaseConnection::__construct() should result in publishing this new object as the one and only database connection being used by TYPO3.
>
> The class is loaded anyway, so no additional performance is lost here. And because of accessing a public property, there is no expensive method call here, too.
>
> The only disadvantage I can see is the possibility to reassign the GLOBALS property (e.g. drop the TSFE and create a new one, don't know why one would do such a thing) without taking care of the static reference of the old one in the class.
>
> We can even completely drop the former $GLOBALS in the very first step of migration and introduce a LegacyGlobalObjects(OrWhateverWeCallThatThingyAfterAll) script which creates references back to the original $GLOBALS places. Then just deprecate all of those globals and in two versions drop the LegacyGlobalObjects mapper file.
>
> I really like the idea of not having $GLOBALS. If it's not the fact that they are global but that type hinted array properties in general are rarely supported by IDEs, I would like to see such a thing as soon as possible.
>
>
> Regards,
>
>
>
> Stephan Schuler
> Web-Entwickler
>
> Telefon: +49 (911) 539909 - 0
> E-Mail: Stephan.Schuler at netlogix.de
> Website: media.netlogix.de
>
>
>
> -----------------------------
> Steigern Sie Ihre Performance
> Melden Sie sich an zum kostenlosen Webinar VMware / vSphere Operations Management am 01. April 2014 und lernen Sie, wie Sie Ihre Hardware effektiver nutzen.
> Jetzt anmelden unter http://it-training.netlogix.de/angebote/webinare/vmware-vsphere-with-operations-management
> ------------------------------------
> Microsoft Office 365 - Alles Cloud, ...oder was?
> Erfahren Sie bei unserem Office 365 Event am 04. April 2014, welche Chancen Office 365 für Ihr Unternehmen bietet.
> Jetzt anmelden unter http://it-training.netlogix.de/angebote/events/office-365-event
> -----------------------------
>
>
>
> --
> netlogix GmbH & Co. KG
> IT-Services | IT-Training | Media
> Neuwieder Straße 10 | 90411 Nürnberg
> Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
> E-Mail: info at netlogix.de | Internet: http://www.netlogix.de
>
> netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
> Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
> Umsatzsteuer-Identifikationsnummer: DE 233472254
> Geschäftsführer: Stefan Buchta, Matthias Schmidt
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: typo3-team-core-bounces at lists.typo3.org [mailto:typo3-team-core-bounces at lists.typo3.org] Im Auftrag von Stefano Cecere
> Gesendet: Donnerstag, 20. März 2014 13:26
> An: typo3-team-core at lists.typo3.org
> Betreff: Re: [TYPO3-core] Wrapper methods around globals?
>
> François.. incredible this morning i came to the same solution (after days of struggling with complex $GLOBALS['TYPO3_DB'] queries) and just posted in the dev list the tip
>
> i don't mind if it's a little slower (i decided to not deploy anymore code that isn't full clean from PhpStorm :)
>
> stefano
>
> On 19/03/14 11:42, François Suter wrote:
>> Hi all,
>>
>> In a patch I submitted this morning [1], I added a wrapper method
>> around $GLOBALS['BE_USER'], because it makes it much easier to work
>> with such globals in an IDE, having type hinting and code completion.
>> I did it because I saw other places in the Core using this way of doing this.
>>
>> Now Kay Strobach thinks this should not be done for performance reasons.
>> Do we have guidelines about this?
>>
>> I'm perfectly willing to update my patch and remove that wrapper
>> method, but I would first like to know if there's any consensus about this.
>>
>> Cheers
>>
>
>
> --
>
> -- --- ----- -------
>
> Stefano Cecere
> KRUR studio - http://krur.com
> _______________________________________________
> Before posting to this list, please have a look to the posting rules on the following websites:
>
> http://typo3.org/teams/core/core-mailinglist-rules/
> http://typo3.org/development/bug-fixing/diff-and-patch/
> _______________________________________________
> TYPO3-team-core mailing list
> TYPO3-team-core at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-team-core
>



More information about the TYPO3-team-core mailing list