简体   繁体   中英

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"
}

It works fine for me, any case checking GET/POST existing with isset()/empty() always good

<?
   $sizex = isset($_GET['sizex']) ? $_GET['sizex'] : 200; 
?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM