Why declare PHP variable type in a comment?

前端 未结 5 2068
[愿得一人]
[愿得一人] 2021-02-02 09:51

I\'m fairly new to PHP, and I just started using NetBeans to develop my PHP code.

Out of the blue, as I entered a variable in a query, a dialog popped up and asked me to

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 10:22

    I guess you're talking about something like that:

    /**
     * @var SimpleXMLElement $xml
     */
    private $xml;
    

    This is so called phpDoc comment. It allows you to generate API documentation (like this one for instance). Furthermore, most IDEs including Eclipse and NetBeans also support that syntax, and provide dynamic code completion etc.

提交回复
热议问题