Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Alcoy (Spain)
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    An @ before a function

    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.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    The @ surpresses any errors that might be found

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Alcoy (Spain)
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!! Now you've mention it i remeber that i've read somethig sometime ago.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ill make this thread sticky for awhile as it is good to know and nearly impossible to find in the PHP documentation.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Originally posted by Jeewhizz
    http://www.php.net/manual/en/languag...rorcontrol.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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New Coder
    Join Date
    Sep 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hrmm is that similar to something like this

    @mysql_query(" ........ ");

    also to suppress errors? (why use it if you have or die(" ")

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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

  • #9
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    function query($sql)
    {
          
    $sql mysql_query($sql);
          
    reutrn $sql;
    }
    @
    query("..."); 
    or would it have to be:

    PHP Code:
    function query($sql)
    {
          
    $sql = @mysql_query($sql);
          return 
    $sql;

    Thanks

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Take note that the error still kills the script, you just don't receive an error.

    PHP Code:
    <?php

    print "aa";
    @print 
    cal();
    print 
    "bb";

    //prints "aa" only

    ?>
    In response to missing-score's post, give it a try:

    PHP Code:
    <?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.

  • #11
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.

    Im running the latest version of PHP on kryceks hosting.

    I didnt know it still killed it.


    Thanks tho.

  • #12
    New Coder
    Join Date
    May 2003
    Location
    Groningen, the Netherlands
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

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