autocomplete with object in $GLOBALS array
hi
one of the CMS I use have some objects stored in $GLOBALS array.
Is there any way to make autocomplete with such object?
This doesn't work: :(
/** @var $GLOBALS['TYPO3_DB'] t3lib_DB */
$GLOBALS['TYPO3_DB']->...autocomlpete here....
Please sign in to leave a comment.
Hi Krystian,
Currently it is not possible to give type hint to a specific array element. There is already a feature request on Issue Tracker, but I cannot find it right now.
You are using $GLOBALS to access global variables from within functions/class methods. Can you use global $varname; approach instead? Have a look at this dummy example:
No - this is not possible to use it like that.
The arrray of objects inside the $GLOBALS array is build during init of the CMS. No way to change that.
Where are you trying to use this type hinting -- in your own code or inside CMS classes (i.e. you are developer of that CMS)?
If first -- then I don't really see why it is not possible. In CMS classes you access global variables via $GLOABALS (you do not need to edit those files anyway, unless you are trying to fix some bugs) and in your own code via global keyword.
You can even mix them within the same function if necessary.
Well is works but IMO adding new line
global $boom;
just to get autocomplete is not a clean solution.
I can not accept that in my code.
Well, I just suggested you a way how it can be achieved in current version of PhpStorm. It is up to you to use it or to wait until type hinting for individual array element will be implemented.
Thanks for your time Andriy !
Looks like it's still the same.
For now the most elegant way to use autocomplete is this: `global $boom; $boom...` in one line.
@Bence Szalai
Have a look at deep-assoc-completion plugin -- it has quite a few mechanics that may work with $_GLOBALS as well (thankfully, I never had to use $_GLOBALS myself).
@Andriy Bazanov
I did a quick test. For me, looks like it does not work with $_GLOBALS, but very usefull plugin nevertheless, so thanks for the recommendation!