Reputation: 13
I tried to understand this line of code, but it is failed.
$this->request->{self::FLAG_SHOW_CONFIG} === 'true'
I have no keyword to search for this kind of syntax.
What does it means.
How come they have "===" instead of "==" ?
How come they can do $this->request->{self::FLAG_SHOW_CONFIG}, while, the FLAG_SHOW_CONFIG is a field of $this, it is not belong to $this-> request
The full code is
<?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();
}
}
?>
Upvotes: 1
Views: 339
Reputation: 9858
The $this->request->{self::FLAG_SHOW_CONFIG}
is interpreted by PHP as $this->request->showConfig
. And the ===
is basically checking for equality in both value and type. Check this page to see the description of the triple equal signs http://php.net/manual/en/language.operators.comparison.php
Also, check this page http://php.net/manual/en/language.variables.variable.php to see about variable variables in PHP.
Upvotes: 1
Reputation: 3539
$this->request->{self::FLAG_SHOW_CONFIG}
is same as:
$this->request->showConfig
Upvotes: 0