我试图从地址栏调用类函数,如下所示:
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';
}
}
但索引功能不会执行。你们认为我在这里做错了什么?
答案 0 :(得分:2)
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();