phan/phan
在 GitHub 查看Support proposed `@global` phpdoc annotations (On function docblocks)
Open
#856 建立於 2017年6月10日
enhancementhelp wanted
描述
https://phpdoc.org/docs/latest/references/phpdoc/tags/global.html suggests it may be in a future docblock.
I assume the syntax would be @global MyClass $someGlobalObject, similar to @var
- This would help users who have issues such as https://github.com/etsy/phan/issues/834 (
globals_type_mapis another option, but mainly useful for things which have dozens or more uses and a unique name)
Suggested Implementation Details
- Warn if the annotation exists, but
global $x;doesn't occur within the scope of the function. global T $xtakes priority overvar T $x- At the point where
global $xis imported, assume it has typeT1if there is an phpdoc comment/** @global T1 $x description */on the function - Deprecate
@var $xon globals, by emitting a new issue type (that issue type can be turned off to suit project requirements) - Type should not leak out of the function, except through assignments to the global variable? Not sure.