Notices

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    Notices

    I'm still coming to grips with Notices, particularly on missing indexes.

    Lets say we have a form full of check boxes. An unchecked checkbox is
    not sent in $_REQUEST and if you do something with
    $_REQUEST['my_checkbox'] you'll get a notice. Is there a clean method of
    dealing with this?

    I'm a recovering perl programmer so conciseness is still important. I
    suppose I'll get over it eventually but I still miss ||= .

    Jeff
  • Sjoerd

    #2
    Re: Notices

    On Aug 9, 9:11 pm, Jeff <jeff@spam_me_n ot.comwrote:
       I'm still coming to grips with Notices, particularly on missing indexes.
    >
       Lets say we have a form full of check boxes. An unchecked checkboxis
    not sent in $_REQUEST and if you do something with
    $_REQUEST['my_checkbox'] you'll get a notice. Is there a clean method of
    dealing with this?
    >
       I'm a recovering perl programmer so conciseness is still important.. I
    suppose I'll get over it eventually but I still miss ||= .
    >
       Jeff
    A typical solution is to configure your PHP to not show notices
    anymore, for they are annoying.

    Alternatively, you may test if there really is a
    $_REQUEST['my_checkbox'] with either of the following:
    isset($_REQUEST['my_checkbox'])
    array_key_exist s('my_checkbox' , $_REQUEST)

    Of course, isset() is a language construct rather than a function.
    That is why you do not get a notice, even though it looks like you are
    referencing $_REQUEST['my_checkbox'].

    Comment

    • Jerry Stuckle

      #3
      Re: Notices

      Jeff wrote:
      I'm still coming to grips with Notices, particularly on missing indexes.
      >
      Lets say we have a form full of check boxes. An unchecked checkbox is
      not sent in $_REQUEST and if you do something with
      $_REQUEST['my_checkbox'] you'll get a notice. Is there a clean method of
      dealing with this?
      >
      I'm a recovering perl programmer so conciseness is still important. I
      suppose I'll get over it eventually but I still miss ||= .
      >
      Jeff
      >
      You should NEVER configure a development server to ignore notices. Each
      one is a potential bug in your program - which is why they are being
      displayed. They are notices to let you know there MAY be a problem. A
      good programmer will fix these notices.

      And it's easy to do. Just use isset() to determine of the checkbox is
      set, or not, i.e.

      $my_checkbox = isset($_POST['my_checkbox']) ? $_POST['my_checkbox'] : '';

      The last value can be an empty string, null, 0 or whatever you want for
      a value when the checkbox is not set.

      Also, you should always user $_POST or $_GET instead of $_REQUEST.
      $_REQUEST gets its data from $_GET, $_POST or $_COOKIE, and can too
      easily cause problems (i.e. what happens if two years from now,
      somewhere else in your program, you call setcookie('my_c heckbox', 1)?

      This code could break, among other things.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Geoff Berrow

        #4
        Re: Notices

        Message-ID: <PZidneldV_Sruj _VnZ2dnUVZ_gedn Z2d@earthlink.c omfrom Jeff
        contained the following:
        >But missing index notices are NEVER harmless! They may not cause a
        >problem now. But they will later.
        >
        >I remain skeptical that an undef has more harmful potential than an
        >empty string.
        when I first started with PHP you used to see a lot of

        if($var){...}

        in tutorials. So naturally I did the same. Recently I was updating an
        old website and I saw that a notice had appeared. Clearly the ISP had
        changed its PHP version to one with a higher level of error reporting.

        --
        Geoff Berrow 011000100110110 0010000000110
        001101101011011 001000110111101 100111001011
        100110001101101 111001011100111 010101101011
        The Slippery Hill Boys Tel: 07985 425932. American themed barn dances and bluegrass performances. Stoke on Trent, Newcastle under Lyme, Staffordshire, Cheshire and surrounding areas.

        Comment

        Working...