You are here: Re: What does @ do? « PHP Programming Language « IT news, forums, messages
Re: What does @ do?

Posted by AnrDaemon on 10/24/07 23:22

Greetings, Good Man.
In reply to Your message dated Thursday, October 25, 2007, 01:36:44,

>>> I am new to php and google doesn't allow for searching on the @
>>> symbol.
>>>
>>> I have a script with the following line:
>>>
>>> if (@$type_toggle || @cat_toggle) {
>>> do_query........
>>>
>>> What does the @ do? Can you give me a link so I can read about it.
>>
>> it surpresses error messages, so that if the variable "$type_toggle"
>> or "$cat_toggle" doesn't exist, error messages/warnings will not be
>> printed to the screen.

GM> and by the way, in relation to the "register_globals" questions that have
GM> gone around the last couple of days, the script above is a perfect example
GM> of why register_globals should be turned off.

GM> if register_globals is on, simply checking for a variable will ALWAYS
GM> return true, so in the code above, $type_toggle and $cat_toggle BOTH exist
GM> and the query will ALWAYS be performed.

Then, to avoid ambiguous comparison, use clarifying functions.

In the example showed above:

if(!empty(@$type_toggle) || !empty(@cat_toggle))
{
do_query........

To make sure You have non-empty array $arr:

if(is_array($arr) && count($arr))
{
do_something();
}

Notice: it is not enough to check for count($var) as far as ordinary variables
always return 1 == count($var), so, construction:
if(count($var))
{
foreach($var as ...)

Will end in "Supplied variable should be an array" in some cases.


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация