I have this code:
$sSomeClass = 'Database'; $pdo = $sSomeClass::getInstance();
Is there any way how to typehint in PHPDoc, that variable “$sSomeClass” is a class name, so IDE can see a reference to that class?
Advertisement
Answer
Well…
<?php /** * * @var Database $sSomeClass */
But I assume $sSomeClass is not a straight assignment like shown? In that case… possibly? IDE wouldn’t be able to determine it, might be able to scope the hints inside curly braces. Will depend on IDE.
if ($foo == 'bar') {
/**
*
* @var Bar $sSomeClass
*/
$sSomeClass = 'Bar';
} else {
/**
*
* @var Foo $sSomeClass
*/
$sSomeClass = 'Foo';
}
I’ll add blocks like that C style comment when coding if struggling to remember methods and then simply remove it afterward.