我收到以下错误:
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in localhost\websites\mvc-pattern\app\start\Starter.php on line 7
错误行已注明//this is the error line
这是我的代码:
<?php
class Starter{
protected $controller= 'Home';
protected $method= 'index';
protected $param= array();
public function __construct(){
$url=this->url();//this is the error line
// prepare controller
if(file_exists('../app/controllers/' . $url[0] . '.php')){
this->$controller= $url[0];
unset($url[0]);
}
require_once '../app/controllers/'. $controller. '.php';
this->$controller= new this->$controller;
//prepare method
if(isset($url[1])){
if(method_exists($controller,$url[1])){
this->$method= $url[1];
unset($url[1]);
}
}
this->$param= $url ? array_values($url) : array();
call_user_func_array([this->$controller,this->$method],this->$param);
}
public function url(){
$url= $_GET['url'];
$url= explode('/',rtrim($url,'/'));
return $url;
}
}
答案 0 :(得分:2)
this
是未定义的常量...常量不能用作对象。
$url=this->url();//this is the error line
应为$this->url();
- 请注意$
。您在其他多个地方也有同样的错误。