Netbeans代码完成显示无用的信息循环遍历对象


Netbeans code completion shows unusefull information looping through objects

我有以下代码:

    $teamdbCall = new TeamDAL();
    $playersInTeam = $teamdbCall->GetStartedTeams(); //PDO::fetchall result returned
    //var_dump($playersInTeam);
    foreach($playersInTeam as $team)
    {
        /*@var $team Team*/
        echo $team->Name . "<br />";  //GENERATED public property
        echo $team->name . "<br />";  //private property
        echo $team->get_teamname() . "<br />";  //public getter
    }

当运行此操作时,PDO fetchAll()结果将作为对象数组返回到变量$playersInTeam。

当通过var_dump观察数组时,它显示了团队类的私有对象属性(例如小写的"name")。var_dump还显示自动生成的公共属性,这些属性与私有属性相同,但以大写字母开头(例如"Name")。

我尝试在foreach循环中回显结果。第一行:echo $team->Name按预期工作,它显示了名称。第二行不行……因为它是一个私有属性。

但是我想使用第三个版本,一个team对象的公共getter。代码完成只显示那些公共getter,而不显示公共属性和私有属性。

因此,当其他人使用GetStartedTeams()尝试循环时,他需要猜测属性并始终使用大写字母。这很奇怪,因为给出的提示显示了公共getter,可以随时使用。

你知道我该怎么解决这个问题吗?

解决这个问题的方法是将PHPdoc添加到基本的Team类文件

<?php
/**
 * Team class
 *
 * @property $Teamname   //<-- this line makes the code completion usefull
 */
class Team{
    private $teamname;
}
?>