usban
03-17-2003, 10:24 PM
I've got a class downloaded from internet, in this class i have seen pieces of code like that:
if(@strlen($serv[3]) == 3){
...
}
The question is the meaning og the @ before the function. This is only an example because during all the class this happens many times.
Nightfire
03-17-2003, 10:40 PM
The @ surpresses any errors that might be found
usban
03-17-2003, 10:55 PM
Thanks!! Now you've mention it i remeber that i've read somethig sometime ago.
:o
Spookster
03-17-2003, 11:35 PM
Ill make this thread sticky for awhile as it is good to know and nearly impossible to find in the PHP documentation.
Jeewhizz
03-20-2003, 11:24 PM
http://www.php.net/manual/en/language.operators.errorcontrol.php
Here :)
Spookster
03-21-2003, 12:40 AM
Originally posted by Jeewhizz
http://www.php.net/manual/en/language.operators.errorcontrol.php
Here :)
Nice work. I spent much time trying to find that. I had found it once before but it's almost like trying to find a needle in a haystack. :thumbsup:
Roost3r
04-10-2003, 05:31 PM
hrmm is that similar to something like this
@mysql_query(" ........ ");
also to suppress errors? (why use it if you have or die(" ");)
Nightfire
04-10-2003, 05:41 PM
The or die ("...") is so you can have your own error message, obviously. If you do it without the @ you will get your error and the mysql error plastered all over your page, which is then completley pointless having the die message
missing-score
04-22-2003, 01:04 PM
You could also want to put an @ before a function that you need, but if it does not work, you dont want the whole page to fail, eg. Adding a number of times a page has been viewed.
Anyway, my question...
When you write your own functions, can you put an @ before them, eg:
function query($sql)
{
$sql = mysql_query($sql);
reutrn $sql;
}
@query("...");
or would it have to be:
function query($sql)
{
$sql = @mysql_query($sql);
return $sql;
}
Thanks
x_goose_x
04-22-2003, 01:32 PM
Take note that the error still kills the script, you just don't receive an error.
<?php
print "aa";
@print cal();
print "bb";
//prints "aa" only
?>
In response to missing-score's post, give it a try:
<?php
function cal() {
tmp();
}
print "aa";
@print cal();
print "bb";
//prints "aa" only
?>
It has the same effect.
Note that PHP changes quickly and errors may be handled diferently in older versions.
missing-score
04-22-2003, 01:48 PM
Thanks.
Im running the latest version of PHP on kryceks hosting.
I didnt know it still killed it. :confused:
Thanks tho.
harrydb
05-26-2003, 12:49 AM
Originally posted by Roost3r
hrmm is that similar to something like this
@mysql_query(" ........ ");
also to suppress errors? (why use it if you have or die(" ");)
The following code:
mysql_query($query) or print("some error occured");
will print "some error occured" when the query failed and continue with the rest of the page.
Harry.