当我创建这个类的实例时,我得到了错误
Parse error: syntax error, unexpected '__construct' (T_STRING),
expecting variable (T_VARIABLE) on line 9.
这就是我创建实例的方式:
function controller_from_str($controller_name)
{
$controllers_namespace = 'MVCBP\\Controllers\\';
$controller = $controllers_namespace
. $controller_name . 'Controller';
return new $controller();
}
如果我更改__construct()
为UserController()
. 我在 Windows 7 上使用 PHP 5.4。这是预期的行为吗?
这是我的课:
<?php
namespace MVCBP\Controllers;
use MVCBP\Core as Core;
use MVCBP\Models as Models;
use MVCBP\Repositories as Repos;
class UserController implements Core\ControllerInterface
{
private $UserRepo;
public function __construct()
{
$this->UserRepo = new Repos\UserRepository();
}
public function Index()
{
echo '<h1>User</h1>';
}
public function Create()
{
//TODO: if GET/POST
$user = new Models\User();
/*var_dump($user->getDb());*/
render_view('User/Create');
}
private function CreateGet()
{
}
private function CreatePost()
{
}
}