samedi 10 janvier 2015

PHP OR surprising behavior


Vote count:

2




I have some surprising results using OR as a logical OR in php.

Considering the following code:



$a = false;
$b = false;
$c = true;

# Test 1, using OR and assigning to a variable
$value = $a OR $b OR $c;
var_dump( $value );
# return bool(false) but why?

# Test 2, using OR directly in var_dump
var_dump( $a OR $b OR $c );
# return bool(true) as expected

# Test 3, using || and assigning to a variable
$value = $a || $b || $c;
var_dump( $value );
# return bool(true) as expected

# Test 4, using || directly in var_dump
var_dump( $a || $b || $c );
# return bool(true) as expected


Why Test 1 and Test 2 give different results even though they do the same logical operation?



asked 5 mins ago

Eric

971






PHP OR surprising behavior

Aucun commentaire:

Enregistrer un commentaire