I’m trying to improve my coding ninja h4x skills, and I’m currently looking at different frameworks, and I have found sample code that’s pretty hard to google.
I am looking at the FUEL framework used in a project.
The sample I don’t understand is
$data and $this->template->set_global($data);
What is the and keyword doing in this line of code? It is used many places in the framework and it’s the first that I have found that uses it.
This is a type of “short circuit evaluation“. The
and/&&implies that both sides of the comparison must evaluate toTRUE.The item on the left of the
and/&&is evaluated toTRUE/FALSEand ifTRUE, the item on the right is executed and evaluated. If the left item isFALSE, execution halts and the right side isn’t evaluated.Note these don’t have to be actual boolean
TRUE/FALSE, but can also be truthy/falsy values according to PHP’s evaluation rules. See the PHP boolean docs for more info on evaluation rules.