php中关于变量加括号的问题
<?phpclassModel{public$text;publicfunction__construct(){$this->text='Helloworld!';}}c...
<?php
class Model {
public $text;
public function __construct() {
$this->text = 'Hello world!';
}
}
class View {
private $model;
private $controller;
public function __construct(Controller $controller, Model $model) {
$this->controller = $controller;
$this->model = $model;
}
public function output() {
return '<a href="test.php?action=textclicked">' . $this->model->text . '</a>';
}
}
class Controller {
private $model;
public function __construct(Model $model) {
$this->model = $model;
}
public function textClicked() {
$this->model->text = 'Text Updated';
}
}
$model = new Model();
//It is important that the controller and the view share the model
$controller = new Controller($model);
$view = new View($controller, $model);
if (isset($_GET['action'])) $controller->{$_GET['action']}();
echo $view->output();
?>
问题:
$controller->{$_GET['action']},为什么要用{},去掉也可以正常运行 展开
class Model {
public $text;
public function __construct() {
$this->text = 'Hello world!';
}
}
class View {
private $model;
private $controller;
public function __construct(Controller $controller, Model $model) {
$this->controller = $controller;
$this->model = $model;
}
public function output() {
return '<a href="test.php?action=textclicked">' . $this->model->text . '</a>';
}
}
class Controller {
private $model;
public function __construct(Model $model) {
$this->model = $model;
}
public function textClicked() {
$this->model->text = 'Text Updated';
}
}
$model = new Model();
//It is important that the controller and the view share the model
$controller = new Controller($model);
$view = new View($controller, $model);
if (isset($_GET['action'])) $controller->{$_GET['action']}();
echo $view->output();
?>
问题:
$controller->{$_GET['action']},为什么要用{},去掉也可以正常运行 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询