我试图理解这行代码,但它失败了。
$ this-> request-> {self :: FLAG_SHOW_CONFIG} ==='true'
我没有搜索这种语法的关键字。
这意味着什么。
为什么他们有“===”而不是“==”?
他们怎么能做$ this-> request-> {self :: FLAG_SHOW_CONFIG},而FLAG_SHOW_CONFIG是$ this的字段,它不属于$ this->请求
完整的代码是
<?php
class Magentotutorial_Configviewer_Model_Observer {
const FLAG_SHOW_CONFIG = 'showConfig';
const FLAG_SHOW_CONFIG_FORMAT = 'showConfigFormat';
private $request;
public function checkForConfigRequest($observer) {
$this->request = $observer->getEvent()->getData('front')->getRequest();
if($this->request->{self::FLAG_SHOW_CONFIG} === 'true'){
$this->setHeader();
$this->outputConfig();
}
}
?>
答案 0 :(得分:1)
PHP将$this->request->{self::FLAG_SHOW_CONFIG}
解释为$this->request->showConfig
。并且===
基本上检查值和类型的相等性。查看此页面以查看三等号http://php.net/manual/en/language.operators.comparison.php
另外,请查看此页面http://php.net/manual/en/language.variables.variable.php以查看PHP中的变量变量。
答案 1 :(得分:0)
$this->request->{self::FLAG_SHOW_CONFIG}
与:
$this->request->showConfig