Search code examples
phpif-statementgetparse-error

PHP Parse error: syntax error, unexpected '}' with $_GET[] in if { }


I have the following php-code that I don't seem to be able to get working:

<?php
    if($_GET['sizex'] == null) { 
        $sizex = 200; 
    } else { 
        $sizex = $_GET['sizex']; // This is the problematic line
    }
?>

When I try to run it, I get the following error:

PHP Parse error:  syntax error, unexpected '}' in test.php on line 6

I have found out that the $_GET[] causes this, because if I replace it with anything else like $sizex = 1, it works fine. Is there some typo which I cant see, or is there something special about $_GET that I don't know?

var_dump($_GET):

array(1) {
  ["sizex"]=>
  string(1) "1"
}

Solution

  • This code works fine. There is no syntax error there. Probably you have some weird invisible characters. Try to clear all newlines and then insert them back.