Page 1 of 1

[SOLVED] Parse error: syntax error, unexpected T_UNSET

Posted: Tue Dec 25, 2007 1:24 pm
by kendall
Hi everyone....happy christmas! merry new year!

I have an array which can have an index

Code: Select all

$a = NULL; if($_GET['page']) { $a['page'] = $_GET['page']; } // usually set via $_GET/ $_POST else there is not an index of it ;

a couple lines down i have a

Code: Select all

if(isset($a['page'])){ @unset($a['page']); }
usually it is NOT set however i keep getting a PHP error...
Parse error: syntax error, unexpected T_UNSET
I tried doing some background research on this but i don't see anything...what does this mean?

Posted: Tue Dec 25, 2007 1:39 pm
by vigge89
I'm not sure that you can suppress errors fired by unset, hence the parser encountering an unexpected token after the @.
Either way I don't see the point of suppressing it as you're already checking if it's set before.

Posted: Tue Dec 25, 2007 1:49 pm
by Jonah Bron
I think you want this:

Code: Select all

if (isset($_REQUEST['page'])){
    $a['page'] = $_REQUEST['page'];
}

if (isset($a['page'])){
    unset($a['page']);
}

Posted: Tue Dec 25, 2007 10:55 pm
by John Cartwright
Why are you suppressing unset()?

Posted: Wed Dec 26, 2007 5:07 pm
by Chris Corbyn
unset() is not strictly a function... it's a statement. It doesn't generate any warnings when used on variables that don't exist neither. Checking if (isset($var)) simply to do an unset() isn't necessary, however it does make code more readable shows intent.