if(@$variable)

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
bodya
Forum Newbie
Posts: 1
Joined: Mon Aug 09, 2010 6:44 pm

if(@$variable)

Post by bodya »

I usually use syntax

Code: Select all

if(@$variable)
instead of

Code: Select all

if(isset($variable) && $variable)
The first variant is faster but is it correct? Thanks
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: if(@$variable)

Post by josh »

Nope. isset() returns true if the variable is set. the first one differs in that it will not run if the variable is set but set to false. Use isset(). Error suppression is never needed.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: if(@$variable)

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply