Upgrading from PrestaShop 1.6 to 1.7, I found a change in how the developers return the module install method. Obviously, for both the old and new way, you want to return true if ALL is ok, and false 1.6:
public function install() {
if(!$this->someFunction() || !parent::install())
return false;
return true;
}
Sometimes the other way around:
public function install() {
if($this->someFunction() && parent::install())
return true;
return false;
}
But now in 1.7 they do it this way, and I cannot figure out how this even works:
public function install() {
return parent::install()
&& $this->someFunction();
}
How can a function return THIS and THAT? If I was to guess, I would think that it either returns the first TRUE/FALSE and then exits, OR returns the sum of them both (but then only FALSE && FALSE would return FALSE)
Please help me understand this.
return this && that
is read as return (this && that)
. this
and that
will be evaluated to a boolean
. If both are true
, then it becomes return (true && true)
. true && true
evaluates to true
. So, it becomes return true
.
It's Boolean Algebra in code form.