if check with multiple logical operators failing with error

A

Anonymous

Guest
Here is my PHP code:

Code:
<?php

$a = 76;
$b = true;
$c = 0;
$d = 500;

$check = (
            ($a > 0) && 
            ($b == false) && 
            ($c == 0) && 
            ($d > 0)
        );
    
echo '[' . $check . ']' . "\n"; //echoes []

// -------------------------------

$a = 76;
$b = false;
$c = 0;
$d = 500;

$check = (
            ($a > 0) && 
            ($b == false) && 
            ($c == 0) && 
            ($d > 0)
        );
    
echo '[' . $check . ']' . "\n";


?>

This generates this error:

Code:
PHP Fatal error:  Uncaught Error: Call to undefined function  () in /home/abc/code/php_test/test_boolean.php:26
Stack trace:
#0 {main}
  thrown in /home/abc/code/php_test/test_boolean.php on line 26

I can't figure out why this error is occurring. Why does changing $b to false make it think it's a function call?

I get this error if I run it in the browser or on the command line. However, testing it in different online php testers doesn't cause an error and produces the expected output. I don't know why this is causing an error on my local. I tried with both php7.3.31 and php 8.0.12
 
It turned out to be a non-breaking space that was on the line

Code:
($b == false) &&

after the 2nd &. Removing that fixed the issue.
 
Back
Top