Hi there!
I am newbie here, and search along with FAQ didn't answer on my question.
So, the question is:
For instance, I have a class, let's say Application. This class contains application components, such as User, View, etc. All these components are accessed using __get method. The following code may explain this:
class Application
{
/**
* PHP magic __get method.
*
* @param string $name Name of requested variable
* @return mixed
*/
public function __get($name)
{
$getter = 'get' . $name;
if (!method_exists($this, $getter))
throw new Exception('Getter for ' . $name . ' is undefined');
return $this->{$getter}();
}
/**
* Readonly property. Database connection identifier.
*
* @var PDO
*/
private $_db = null;
/**
* Db connection getter. Also if connection is still not established, connects to the mysql server.
* So called lazy loading.
*
* @return PDO
*/
public function GetDb()
{
if ($this->_db == null)
{
$this->_db = new PDO(<some parameters>);
}
return $this->_db;
}
} |
So in my scripts I access my PDO object this way:
$application = new Application();
$db = $application->db;
// now editor don't know what $db is.
$db = $application->GetDb();
// and here phped knows that $db contains PDO object
|
I believe that PhpEd nicely define type of Application::GetDb(), because of @return PDO.
Also Application doesn't have property $db - property _db is accessed instead.
May I somehow appoint, that $application->db actually is the same as _db or may be GetDb?
Thanks a lot, looking forward any answer. Cheers