Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
727 views
in Technique[技术] by (71.8m points)

phpdoc - Variable type hinting in Netbeans (PHP)

Just curious if there's a way in netbeans to give type hints for regular variables, so that intellisense picks it up. I know you can do it for class properties, function parameters, return types, etc. but I can't figure out how to do it for regular variables. It's something that would really help in situations where you have a method that can return different object types (like a service locator).

ex something like:

/**
 * @var Some_Service $someService
 */
$someService = ServiceLocator::locate('someService');

Where using $someService afterward, netbeans would provide all available methods defined in the class Some_Service.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A single line is all you need:

/* @var $varName Type_Name */

See this article in the NetBeans PHP Blog: https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in

Note: At least, in version 8.2; The key seems to be:

  • The single asterisk (/* instead of /**).
  • Placing the type after the variable name.
  • Having nothing before and after the type-hinting (except white-space, but even that is not allowed when the comment is not in a single line).

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...