• (disco)

    $z is false at the end of that expression, because the assignment is actually evaluated before the “OR”.

    I could have told you that.

    In fact... I did tell you that. It's even one of my highest upvoted answers on StackOverflow.

  • (disco) in reply to PleegWat
    PleegWat:
    However, `(int)(double)'3.2e1' != (int)'3.2e1'`

    No repro

    $php -r 'var_dump((int)(double)'3.2e1' != (int)'3.2e1');'
    bool(false)
    

    But TRWTF is your database.

    dkf:
    that seems cromulent (and crazy).

    I agree with your selection of terms here :smile:

  • (disco) in reply to gleemonk

    Fix your quoting

    $ php -r "var_dump((int)(double)'3.2e1');"
    int(32)
    $ php -r "var_dump((int)'3.2e1');"
    int(3)
    $ php -r "var_dump((int)(double)'3.2e1' != (int)'3.2e1');"
    bool(true)
    
  • (disco) in reply to anotherusername
    anotherusername:
    Other than their order of operation, they are exactly the same.

    Well I'll be :wtf: I'd actually assumed or would evaluate to the first non-falsy value. Instead it evaluates to a boolean like ||. Useless fucking operator. No wonder I'd never used it. Hey, now I remember how I tried doing

    $connection = mysql_connect($wtf, $wtf, $wtf, $wtf) or die("mysql can't con me");
    

    and that didn't work because $connection was some shitty boolean. So I promptly forgot about or in my PHP vocabulary.

    PleegWat:
    Fix your quoting

    Whoops, that always gets me :fearful:

  • (disco) in reply to accalia

    Then pick the one you prefer and only use that, I guess.

  • (disco) in reply to gleemonk

    Wait.. it should work here?! Anyway, that's why I don't use it, confuses me everytime.

  • (disco)

    There are already enough posts that reading them all has exceeded my patience threshold, so someone may already have mentioned this, but what the heck...

    You're all blithering about operator precedence when it is quite clear from the article that the problem is not operator precedence but order of operation.

    Or maybe the article is even more :wtf: than PHP, and the writer is even more :wtf: than the article, seeing has how he doesn't know it's called operator precedence...

  • (disco) in reply to Piko
    Piko:
    why would you want to write [such an abomination]?

    Because you're an asshole. Or an idiot. Or both.

  • (disco) in reply to accalia
    accalia:
    ah. so PHP really is TFWTF

    I bet you're not even surprised!

  • (disco) in reply to gleemonk
    gleemonk:
    Nobody tried my bonus WTF, did you?

    I could do that, but then I'd have PHP on me.

  • (disco) in reply to Michael_Mahn
    Michael_Mahn:
    "in fact the same as Perl"

    I think you answered your own question.

    I've been using both Perl and PHP for over 10 years and have never used or in PHP. But it's common in Perl: my $fh = doSomething or die;. I think or is a bit of a wart (especially in PHP) and should be ignored and never used. Use || which every other language uses!

  • (disco) in reply to Zemm
    Zemm:
    Use || which every other language uses!
    SELECT 1 || 0 from dual
    
    10
    

    Hmm.

    :tropical_drink:

  • (disco) in reply to BobbyTables

    3v4l.org should be your site of choice for demonstrating PHP wtfery. You submit code, they run it on every version.

    http://3v4l.org/SHm0H

  • (disco) in reply to riking

    http://3v4l.org/SHm0H/perf#tabs

    [image]

    that's an interesting trend for performance as you get to more and more recent versions of PHP

  • (disco) in reply to accalia

    Woah, yeah... Most programming languages get FASTER as they age.

    At least, all the ones I can think about right now.

  • (disco) in reply to riking
    riking:
    Most programming languages get FASTER as they age.

    most languages aren't PHP.

  • (disco)

    A rant on the design of PHP? What is this, 2005?

    PHP 'or' is not the Python 'or', period. It sounds like you're trying to make a case that it's a good idea to ever use a keyword from another language without having a clue what it means in the one in front of you. Stick to the C-style || or just pretend PHP never happened.

  • (disco) in reply to FrostCat
    FrostCat:
    I could do that, but then I'd have PHP on me.

    With most things it's best to remain ignorant if at all possible, I agree. PHP is in that category.

  • (disco) in reply to gleemonk

    This is from Perl which also has the || and or operators.

    sub test {
        my $var = shift() or die "Function test requires at least one true parameter\n";
    }
    
  • (disco) in reply to John_Imrie

    Get rid of those unnecessary parentheses on the shift!

  • (disco)

    I am disappointed. I was expecting an article pointing out stupid code. Not a stupid language.

  • (disco) in reply to John_Imrie
    John_Imrie:
    This is from Perl which also has the || and *or* operators.

    Well, no contest. Actually in Perl they are useful because

    The ||, // and && operators return the last value evaluated (unlike C's ||, and &&, which return 0 or 1PHP's ||, or, and &&, which return FALSE or TRUE). (perldoc.perl.org)

    Ok, I realise I'm railing against the fact that in PHP || evaluates to boolean. That or does so too is actually just consistent which is what @TheCPUWizard was getting at. I'll shut up now about this downgrade of a language.

  • (disco)

    I really don't understand all the hatred for PHP. It is a widely used language and many sites are implemented using PHP. PHP is a stupid language only if the developer is an idiot.

  • (disco) in reply to Costas_Anastasiou
    Costas_Anastasiou:
    I really don't understand all the hatred for PHP. It is a widely used language and many sites are implemented using PHP. PHP is a stupid language only if the developer is an idiot.

    PHP is also a fantastic idiot-developer-enabler -- instead of barfing on bad code, it plods on, blithely appearing to work while leaving the next dev a landmine to untangle.

  • (disco) in reply to Costas_Anastasiou
    Costas_Anastasiou:
    It is a widely used language and many sites are implemented using PHP.

    That is an understatement. The latest stats show that 81.9% of websites are coded using PHP, while the "perfect language" ASP.NET is used only on 16.9%

    I've been using PHP for about 15 years, so I've seen my share of WTF. But you can make perfectly fine code in PHP if you know what you're doing.

  • (disco) in reply to TimeBandit
    TimeBandit:
    But you can make perfectly fine code in PHP if you know what you're doing.

    Then we may as well write all our code in Shakespeare and Piet.

    Some languages are easier to get things right in, and are better as a result. Just because you've seen a working program written in Malbolge does not mean that it is a good language.

  • (disco) in reply to Magus
    Magus:
    \Some languages are easier to get things right in, and are better as a result. Just because you've seen a working program written in Malbolge does not mean that it is a good language.
    And just because I've seen terrible program written in C# doesn't mean it's a bad language
  • (disco) in reply to Magus
    Magus:
    Just because you've seen a working program written in Malbolge does not mean that it is a good language.

    Has anyone actually done that aside from the guy who used genetic algorithms or whatever to evolve Hello World?

  • (disco) in reply to FrostCat

    Someone wrote 99 bottles in it apparently. But no, it's an awful language. Like php.

  • Axel (unregistered)

    A site full of pedants doesn't twig to the misspelling of "truly"?

  • Axel (unregistered)

    Yeah, yeah, I know it's supposed to be a joke, but it's too--you know--subtle. Spell it "true-ly," is my advice.

Leave a comment on “Truely Representative”

Log In or post as a guest

Replying to comment #453762:

« Return to Article