turning off notices

Discussion in 'PHP' started by promotingspace.net, Aug 17, 2007.

  1. #1
    Hi
    how can i turn off notices ( for undefined variables for example)
     
    promotingspace.net, Aug 17, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
         // turn off all error reporting
         error_reporting(0);
    
         // rest of your code goes here
    ?>
    
    PHP:
     
    sea otter, Aug 17, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    That would turn off all errors. If you just want to hide the notices, set it to its default value.
    
    error_reporting(E_ALL ^ E_NOTICE);
    
    PHP:

    Although, you should design your application in a way that it doesn't show any errors or notices while error reporting is set to E_ALL.
     
    nico_swd, Aug 18, 2007 IP
  4. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can just add a command to each function you call with the @ this will stop errors from being displayed. Something like,

    
    // function
    mysql_num_rows($query);// shows error
    @mysql_num_rows($query);// hides error
    
    Code (markup):
     
    HuggyCT2, Aug 18, 2007 IP
  5. sabmalik

    sabmalik Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    adding an @ works for function calls but you will still get the notices regarding undefined variables. As nico said ..
    error_reporting(E_ALL ^ E_NOTICE);

    Or if that doesnt work for you , you should set a php flag in .htaccess file to that effect.
     
    sabmalik, Aug 18, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    You can use the @ operator for variables too.
    
    if (@$_GET['do'] == 'something')
    {
    }
    
    PHP:
     
    nico_swd, Aug 18, 2007 IP
  7. sabmalik

    sabmalik Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    that is correct, my apologies. what i actually wanted to say was that it is good practice for function calls but not variables.
     
    sabmalik, Aug 18, 2007 IP