Results 1 to 6 of 6

Thread: In PHP why is (0=='string')

  1. #1
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,304
    Distro
    Xubuntu 13.04 Raring Ringtail

    In PHP why is (0=='string')

    PHP Code:
    #!/usr/bin/php
    <?php
    if(0=="string")
            echo 
    "Mind Blown\n";
    else
            echo 
    "All is right in the world\n";
    ?>
    Code:
    ~$ php /tmp/test
    Mind Blown
    Last edited by pqwoerituytrueiwoq; July 7th, 2013 at 07:15 PM.
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,119
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: In PHP why is (0=='string')

    Why? Because...
    http://php.net/manual/en/language.op...comparison.php "If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value."

    and...
    http://www.php.net/manual/en/languag...ing.conversion "If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero)."

  3. #3
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,452

    Re: In PHP why is (0=='string')

    Welcome to figuring out why PHP frankly just sucks
    LambdaGrok. | #ubuntu-programming on FreeNode

  4. #4
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,304
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: In PHP why is (0=='string')

    thanks spjackson
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  5. #5
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: In PHP why is (0=='string')

    Obligatory "PHP: a fractal of bad design" http://me.veekun.com/blog/2012/04/09...of-bad-design/

  6. #6
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,304
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: In PHP why is (0=='string')

    But if it is in php as opposed to javascript you don't have to worry about IE screwing something up, all it has to do is fail at rendering the output
    i am self taught in javascript, and when i started using php it just came to me fairly quickly and easily
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

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
  •