views:

356

answers:

4

Since a couple of months ago my website was full of notice errors so I'm trying to fix the code now. I suppose there was some php update. I'm not so bright at php so:

switch ( (isset($_GET['action'])) ) {

case "delete":
delete();
break;

}

this won't work when I add isset.

Can't you use isset inside a function? I dont know really so I'm asking you guys that know these things.

cheers

+1  A: 

That is because isset returns true or false, not a string (which is what your case statements expect).

Andrew Hare
+1  A: 

isset() returns bool (true or false). You want to call isset() before switch. Example:

if (isset($_GET['action']))
{
  switch($_GET['action'])
  {
    ...
  }
}
anthony
A: 

You need to check isset() before you go into the switch.

AndyMcKenna
+4  A: 

isset returns a bool (see the isset manual page). Your case won't work, as 'deleted' is not a valid boolean value (it evaluates to true I think, but still).

You should check if it's set first, then switch:

if(isset($_GET['action')) {
  switch ( $_GET['action']) ) {
    case "delete":
      delete();
      break;
  }
} else {
  ...
}
Erik van Brakel