Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Oh the Shame [moved]

Oh the Shame [moved]

Scheduled Pinned Locked Moved Clever Code
phphelpquestion
5 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bradml
    wrote on last edited by
    #1

    Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:

    //Something like:
    switch($isValid){

    case true:
           echo 'Valid data';
        break;

    case 'email'
            echo 'Invalid Email';
        break;

    /*
           An so on and so forth
        */
    }

    Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.


    Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

    -- moved by Ed. at 12:20 Sunday 4th March, 2007

    H V D 3 Replies Last reply
    0
    • B Bradml

      Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:

      //Something like:
      switch($isValid){

      case true:
             echo 'Valid data';
          break;

      case 'email'
              echo 'Invalid Email';
          break;

      /*
             An so on and so forth
          */
      }

      Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.


      Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

      -- moved by Ed. at 12:20 Sunday 4th March, 2007

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Bradml wrote:

      Is this forum replacing "subtle bugs'?

      I believe no. Subtle bugs forum is for bugs that were hard to discover, but were fixed. You should not feel ashamed of posting such bugs. Hall of Shame forum is for bugs that could be considered (unforced errors) in Tennis world. An experienced developer should never make such bugs before 2AM. One should feel ashamed when posting such a bug, but it's OK. All your fellow developers had such bugs.


      Hesham A. Amin blog

      1 Reply Last reply
      0
      • B Bradml

        Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:

        //Something like:
        switch($isValid){

        case true:
               echo 'Valid data';
            break;

        case 'email'
                echo 'Invalid Email';
            break;

        /*
               An so on and so forth
            */
        }

        Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.


        Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

        -- moved by Ed. at 12:20 Sunday 4th March, 2007

        V Offline
        V Offline
        Vasudevan Deepak Kumar
        wrote on last edited by
        #3

        Even JavaScript "true" is treated as string I guess. :)

        Vasudevan Deepak Kumar Personal Homepage Tech Gossips

        B 1 Reply Last reply
        0
        • V Vasudevan Deepak Kumar

          Even JavaScript "true" is treated as string I guess. :)

          Vasudevan Deepak Kumar Personal Homepage Tech Gossips

          B Offline
          B Offline
          Bradml
          wrote on last edited by
          #4

          See those three letters that spell "PHP"?


          Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

          1 Reply Last reply
          0
          • B Bradml

            Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:

            //Something like:
            switch($isValid){

            case true:
                   echo 'Valid data';
                break;

            case 'email'
                    echo 'Invalid Email';
                break;

            /*
                   An so on and so forth
                */
            }

            Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.


            Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

            -- moved by Ed. at 12:20 Sunday 4th March, 2007

            D Offline
            D Offline
            Daniel Grunwald
            wrote on last edited by
            #5

            So you compare a string with a bool - doesn't that cause an implicit conversion? It's long ago that I used PHP, but it might be strange enough to convert every non-empty string to true (instead of the more obvious conversion: converting the bool to string). I remember something about the === operator for comparisons with true/false as error codes to prevent implicit conversions, switch probably only uses ==. Also, you forgot the ':' after case 'email'.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups