PHP函数不执行

PHP函数不执行,php,Php,我正试图从地址栏调用一个类函数,如下所示: http://localhost:82/spam_fetcher.php?rm=index 我的剧本是: class Spam_fetcher{ public function __construct() { if (isset($_GET['rm']) && method_exists('Spam_fetcher', $_GET['rm'])) { $view = new

我正试图从地址栏调用一个类函数,如下所示:

http://localhost:82/spam_fetcher.php?rm=index
我的剧本是:

  class Spam_fetcher{
    public function __construct()
    {
        if (isset($_GET['rm']) && method_exists('Spam_fetcher', $_GET['rm'])) {
            $view = new Spam_fetcher();
            $view->$_GET['rm']();
        }
        else
        {
            echo "No such a function";
        }
    }

    public function index()
    {
        echo 'something';
    }
}

但索引函数不执行。你们认为我在这里做错了什么?

错误的地方:你们没有显示你们的代码&你们在哪里调用了你们的方法?你们的脚本中正在执行什么代码?你们只是定义一个类,实际上并没有实例化或调用它(据我们所见)。我想调用index()然后呼应出你的建议是什么?
$sf=newspam\u fetcher$sf->index()+1,您还应该解释对代码所做的更改,例如添加$this、创建新实例、删除
新垃圾邮件抓取器()。。等等。
$this->$\u GET['rm']()可能的代码注入。如果不先检查用户输入或至少转义用户输入,就永远不要这样做。
class Spam_fetcher{
    public function __construct()
    {
        if (isset($_GET['rm']) && method_exists($this, $_GET['rm'])) {
           $this->$_GET['rm']();
        }
        else
        {
            echo "No such a function";
        }
    }

    public function index()
    {
        echo 'something';
    }
}

$view = new Spam_fetcher();