In the spirit of seeing Short-circuit evaluation like Python's "and" while storing results of checks I decided to see how this could be best solved in PHP but I've run into an issue.
unexpected
<?php
function check_a()
{
return 'A';
}
function check_b()
{
return 'B';
}
function check_c()
{
return 'C';
}
if($a = check_a() && $b = check_b() && $c = check_c())
{
var_dump($a);
var_dump($b);
var_dump($c);
}
Results in:
bool(true)
bool(true)
string(1) "C"
code for what I wanted to happen
<?php
function check_a()
{
return 'A';
}
function check_b()
{
return 'B';
}
function check_c()
{
return 'C';
}
// if(($a = check_a()) && ($b = check_b()) && $c = check_c()) // equivalent to line below
if(($a = check_a()) && ($b = check_b()) && ($c = check_c()))
{
var_dump($a);
var_dump($b);
var_dump($c);
}
Results in:
string(1) "A"
string(1) "B"
string(1) "C"
Why does the unexpected example act in this way?