Reference class attributes in strings
Hello,
If I have the following class with the PhpDoc above:
/**
* @property int|null $id
* @property string|null $name
*/
class Profile {
const DB_TABLE = 'profiles';
}
And then somewhere else in the project, in completely different file I have something like this:
$query = 'SELECT * FROM '.Profile::DB_TABLE.' WHERE id = ? OR name = ?';
Is there any chance that something exists where I can tell PhpStorm that the above query uses the properties `id` and `name` from the Profile class? Ideally, I would want to Cmd + Click on the class attribute from PhpDoc and show this query as one of the usages of the selected property.
One way that I found would be this:
/**
* @uses Profile::$id
* @uses Profile::$name
*/
$query = 'SELECT * FROM '.Profile::DB_TABLE.' WHERE id = ? OR name = ?';
But the downside is that I would need to write the property name twice. Once in PhpDoc and once in the query. Is there any other way where I can avoid writing it twice?
Thanks!
Please sign in to leave a comment.