I have following code:
$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
}
When running this, a PDO fetchAll() result is being returned as an array of objects to variable $playersInTeam.
When watching the array through var_dump it shows the private object properties of the team class (lowercase "name" for example). var_dump also shows automatically generated public properties, those are the same as the private but start with a capital ("Name" for example).
I try to echo the results inside the foreach loop. The first line: echo $team->Name works as expected, it shows the name. The second line, doesn't work...as expected because it's a private property.
But I would like to use the third version, a public getter of the team object. Code completion only shows those public getters, and not the public properties nor private properties.
So when someone else using GetStartedTeams() tries looping, he needs to guess the properties and always use a capital. Which is strange because the hints given show public getters, ready to use.
Any idea how I can solve this issue?
The solution to this problem is to add PHPdoc to the basic Team class file
<?php
/**
* Team class
*
* @property $Teamname //<-- this line makes the code completion usefull
*/
class Team{
private $teamname;
}
?>