[SOLVED] Parse error: syntax error, unexpected T_UNSET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

[SOLVED] Parse error: syntax error, unexpected T_UNSET

Post 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?
Last edited by kendall on Wed Dec 26, 2007 5:37 am, edited 1 time in total.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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']);
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Why are you suppressing unset()?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Post Reply