PHP:变量函数名称(函数指针)称为;如何告诉IDE我的函数被调用? [英] PHP: Variable function name (function pointer) called ; How to tell IDE my function is called?
问题描述
我目前正在尝试从我的PHPStorm提供给我的检查工具中删除项目中存在的所有错误和警告.
I'm currently trying to remove all errors and warnings I have in my project the Inspection tool from my PHPStorm give to me.
我遇到一个摘要,PHPStorm在实际使用时以动态方式显示未使用的私有方法_xxx".这是一个简化的代码段:
I encounter a snippet PHPStorm says "Unused private method _xxx" while it's actually used, but in a dynamical way. Here is a simplifyed snippet:
<?php
class A
{
private function _iAmUsed()
{
//Do Stuff...
}
public function run($whoAreYou)
{
$methodName = '_iAm' . $whoAreYou;
if (method_exists($this, $methodName)) {
$this->$methodName();
}
}
}
$a = new A();
$a->run('Used');
?>
在此代码段中,PHPStorm会告诉我未使用的私有方法_iAmUsed",而实际上,它已被使用... 通过添加PHPDocs或其他方法,如何使我的IDE理解我的方法被实际使用?
In this snippet, PHPStorm will tell me "Unused private method _iAmUsed" while, in fact, it is used... How can I, by adding PHPDocs or something, whatever, make my IDE understand my method is actually used?
请注意,我给我的运行"调用一个静态字符串,但是我们也可以想象得到这一点:
Note that I give to my "run" call, a static string, but we can imagine also this:
<?php
$a->run($_POST['whoYouAre']); //$_POST['whoYouAre'] == 'Used'
?>
非常感谢!
推荐答案
在phpdoc中将使用的方法标记为@used 例子
mark used methods in phpdoc as @used example
/**
* @uses _iAmUsed()
* @param string $whoAreYou
*/
public function run($whoAreYou)
{
$methodName = '_iAm' . $whoAreYou;
if (method_exists($this, $methodName)) {
$this->$methodName();
}
}
这篇关于PHP:变量函数名称(函数指针)称为;如何告诉IDE我的函数被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!