phan/phan

Support proposed `@global` phpdoc annotations (On function docblocks)

Open

#856 建立於 2017年6月10日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)PHP (5,455 star) (373 fork)batch import
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_map is 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 $x takes priority over var T $x
  • At the point where global $x is imported, assume it has type T1 if there is an phpdoc comment /** @global T1 $x description */ on the function
  • Deprecate @var $x on 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.

貢獻者指南

Support proposed `@global` phpdoc annotations (On function docblocks) · phan/phan#856 | Good First Issue