Posted by Richard Lynch on 10/04/52 11:08
D_C wrote:
> I often use this type of construct
>
> $cmd = $_POST['cmd'];
> if ($cmd == null) { // do default
>
> but this throws a notice if the ['cmd'] index is not defined. ugly.
> using
>
> if (isset($_POST['cmd'] ) {
> $cmd = $_POST['cmd'];
> }
>
> seems lengthy. is there a way around this?
>
> i tried using
> $cmd = @ $_POST['cmd'];
>
> to suppress errors but didnt seem to have ay effect.
You could maybe put the @ in front of the $cmd:
@$cmd = $_POST['cmd'];
However, I think it would be most clear to do:
$cmd = isset($_POST['cmd']) ? $_POST['cmd'] : NULL;
You can then rest assured that $cmd *IS* set in the rest of your script.
It's a bit lengthy, but at least it's all on one concise line, and you can
easily copy/paste and comment in/out the line.
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|