SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    India
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why some use @ before functions ?

    Hi,

    Why some use @ before php functions ?

    For example

    @mysql_query($sql);

    Here is an code from http://in.php.net/mysql_query

    PHP Code:
    <?
    function q($query,$assoc=1) {
        
    $r = @mysql_query($query);
        if( 
    mysql_errno() ) {
            
    $error 'MYSQL ERROR #'.mysql_errno().' : <small>' mysql_error(). '</small><br><VAR>$query</VAR>';
            echo(
    $error); return FALSE;
        }
    Thanks,

    Yujin

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The @ before a function is an error message supression. You can use this and your code will continue to execute even if there is an error with the function, but if the results of your code are not what you expect and you are looking for causes you might want to leave these out of your code.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    India
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply.

    Have another question. I use code like

    PHP Code:
    $result mysql_query($query); 
    If i do not use $result, can i just use

    PHP Code:
    mysql_query($query); 
    When i use like $result = mysql_query($query); ZendStudio says "Expression result is never used"

    Removing "$result = " part is correct thing if i have no use of the result ?

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    One of the worst things php has, with all warnings and crap, why wouldn't they just use exceptions, which are already there in php5 since long ago. Gives me real headaches at times.</rant>
    Saul

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HostOnNet View Post
    Thanks for the reply.

    Have another question. I use code like

    PHP Code:
    $result mysql_query($query); 
    If i do not use $result, can i just use

    PHP Code:
    mysql_query($query); 
    When i use like $result = mysql_query($query); ZendStudio says "Expression result is never used"

    Removing "$result = " part is correct thing if i have no use of the result ?
    Sure
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •