Re: What does @ do?
am 24.10.2007 23:35:00 von Good Man
trading_jacks wrote in
news:1193259058.228187.211090@k35g2000prh.googlegroups.com:
> 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.
Re: What does @ do?
am 24.10.2007 23:36:44 von Good Man
Good Man wrote in
news:Xns99D3B2DF71774sonicyouth@216.196.97.131:
> trading_jacks wrote in
> news:1193259058.228187.211090@k35g2000prh.googlegroups.com:
>
>> 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.
and by the way, in relation to the "register_globals" questions that have
gone around the last couple of days, the script above is a perfect example
of why register_globals should be turned off.
if register_globals is on, simply checking for a variable will ALWAYS
return true, so in the code above, $type_toggle and $cat_toggle BOTH exist
and the query will ALWAYS be performed.
Re: What does @ do?
am 25.10.2007 01:22:07 von AnrDaemon
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