• (disco)

    setProcessing((boolean)'Frist')

  • (disco)

    It seems there was a need to pad that single line of code... Please reclassify as "ranticle".

  • (disco)

    Someone really needs to have a look at the CSS on the main site:

    [image]

    Chrome 43.0.2357.125 (Linux.)

  • (disco)

    Best ad, would read again.

  • (disco) in reply to PJH

    Blame bad handling of "float" CSS- fixed now.

  • (disco)

    How is this a WTF? Orders of precedence is documented and is in fact the same as Perl.

    This article is by someone who thinks that 1+2*3 is 9.

  • (disco) in reply to Zemm

    "in fact the same as Perl"

    I think you answered your own question.

  • (disco)

    Is there any reason at all for the assignment operators not to have the lowest precedence?

  • (disco) in reply to dahaka

    because PHP is special?

  • (disco)

    $v = my_function() or $v = "default";

    is one reason for the lower precedence of "or"..... RTFM.

  • (disco) in reply to TheCPUWizard

    why would you want to write --> $v = my_function() or $v = "default"; instead of --> $v = my_function() or "default"; ??

  • (disco) in reply to Piko

    If you stick stuff in backticks it will inline-format your code so it's easier to differentiate it from the actual commentary...

  • (disco) in reply to Piko
    Piko:
    why would you want to write

    That was a trivial example. What if you wanted to assign $other to something in the event that my_function returned false??? The 'or' can (in many cases) be used for concepts like:

    $v = func();
    if (!$v) { ????? }
    
  • (disco) in reply to TheCPUWizard

    You could have an or operator to ease assignement like $foo = $bar or $preset;, or you could have a fucked up operator that works in a totally unexpected way. I guess using it with $foo = ($bar or $preset); is not that bad, until you forget the parens and wonder why shit fails.

  • (disco) in reply to gleemonk

    C# invented the ?? operator ...

  • (disco) in reply to gleemonk

    /me wonders if PHP is sane with its type coersion and

    $foo = $bar || $preset

    works correctly like it does in JS or not

  • (disco) in reply to accalia

    JS is more relaxed here. PHP || coerces to boolean, so it only works right with flags.

  • (disco) in reply to gleemonk

    ah. so PHP really is TFWTF

  • (disco) in reply to accalia

    Here is the code for a [fiddle][1]

    <?php
    $x = "";
    $y = "FILE_NOT_FOUND";
    
    $z = $x || $y;
    
    $alphabetOverflow = $x OR $alphabetOverflow = $y;
    
    echo "\$z is $z <br/>";
    echo "\$alphabetOverflow is \$alphabetOverflow";
    ?>
    

    The site wants me to register, and I'm much too lazy for that. [1]: http://phpfiddle.org/

  • (disco) in reply to BobbyTables
    BobbyTables:
    <?php $x = ""; $y = "FILE_NOT_FOUND";

    $z = $x || $y;

    $alphabetOverflow = $x OR $alphabetOverflow = $y;

    echo "$z is $z <br/>"; echo "$alphabetOverflow is $alphabetOverflow"; ?>

    $z is 1 
    $alphabetOverflow is $alphabetOverflow
    

    wtf?

    oh. no i got this. you left an accalia in your fiddle

    $z is 1 
    $alphabetOverflow is FILE_NOT_FOUND
    

    still a :wtf: but this time it's PHP's WTF

  • (disco) in reply to gleemonk
    gleemonk:
    that works in a totally unexpected way

    Only if someone is too arrogant, or lazy, or....to RTFM....Why should anyone be programming in a language that they have not mastered the basics of? I would love to see you make sense out of some good APL

  • (disco)

    BONUS WTF: Try guessing what this will print:

    php -r 'echo(0) or print(1);'
    

    Hint: echo is not a function.

  • (disco) in reply to TheCPUWizard
    TheCPUWizard:
    Why should anyone be programming in a language that they have not mastered the basics of?

    That's not the point. The point is, if you design a product, ( a programming language is a product ) you should try and make it easy for your users. Even if people read the manual, if something works counter-intuitively a mistake is bound to happen.

  • (disco) in reply to TheCPUWizard
    TheCPUWizard:
    Only if someone is too arrogant, or lazy, or....to RTFM....

    It's shit functionality that I've never seen used in a way where it was an improvement to the code. If the precedence were different it would be alot more useful and less dangerous. Didn't know we had APL :trolleybus: service around here.

  • (disco)

    The inevitable FILE_NOT_FOUND comment.

  • (disco) in reply to accalia
    accalia:
    you left an accalia in your fiddle

    Umm, yes. Yes I did. Totally intentional, just to test you. Not at all a copy/paste error. No sir/madam.

  • (disco) in reply to gleemonk
    gleemonk:
    If the precedence were different it would be alot more useful and less dangerous

    If the precedence was the same as || then it would simply be a duplicate [see Scott Meyers' comments on "Don't mollycoddle your users"], is it was very similar, but with a subtle difference, it would be [IMPO] worse. Completely different term, completely different usage - consistent.

  • (disco) in reply to TheCPUWizard
    TheCPUWizard:
    is it was very similar, but with a subtle difference, it would be [IMPO] worse.

    I can accept this as a reason why you would argue against having the operator. But then we shouldn't have ===, should we? Extremely similar to == in all regards, just subtle differences.

    TheCPUWizard:
    Completely different term, completely different usage - consistentuseless.

    Can you show me an example where this is used in the wild? I mean, an example where readability is improved, and without precedence-enforcing parens. You're arguing that the weird precedence is an advantage, but I don't see it.

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

    Has this ever been in doubt?

  • (disco)

    $dtRecord->setProcessing((boolean)'false');

    would have been a more amusing WTF... at least as stated, the perpetrator can counter with "it works"

  • (disco) in reply to Julia

    I was about to ask, does 'false' get type juggled into the boolean false?

  • (disco) in reply to eViLegion

    No, any string, aside from the empty string and the string "0" would be converted to true.

  • (disco) in reply to BobbyTables

    Excellent! Why the string "0"? That seems a bit weird.

  • (disco) in reply to eViLegion
    eViLegion:
    Excellent! Why the string "0"?
    Because PHP?
    eViLegion:
    That seems a bit weird.
    PHP :smile:
  • (disco) in reply to eViLegion
    eViLegion:
    Why the string "0"? That seems a bit weird.
    I don't PHP, but the same thing is true in Perl.

    "0" == 0; therefore, "0" is false.

  • (disco) in reply to eViLegion
    eViLegion:
    Why the string "0"?

    Because PHP!

    You could argue that a boolean is a very restricted form of a number, then it makes some limited sense. Because then (bool)'0' and (bool)(int)'0' yield the same result. Otherwise you'd have (bool)'0' !== (bool)(int)'0' which would be surprising sometimes.

  • (disco) in reply to gleemonk
    gleemonk:
    which would be surprising sometimes.

    I don't think this is an argument that counts when talking about PHP...

  • (disco) in reply to dahaka

    I was talking from general principles :smile:

  • (disco) in reply to HardwareGeek

    In PHP, the popular way of handling critical errors once used to be something along the lines of mysql_connect() OR die();.

    I found that life threatening, that's why I have avoided PHP ever since.

  • (disco)

    I guess I'm just not used to allowing the language to dick about juggling types. I prefer casts to be explict so that no-one is left in any doubt about exactly whats happening. Maybe I'm just old school.

  • (disco) in reply to gleemonk
    gleemonk:
    Because PHP!

    :hanzo:

  • (disco) in reply to eViLegion
    eViLegion:
    I guess I'm just not used to allowing the language to dick about juggling types.

    Then PHP is not the language for you. (Neither is Perl.)

  • (disco)

    I get the PHP hate. I really do. I've read all the articles. I've experiencesd a lot of the quirks.

    I even do deal with some of the limitations, like the lack of "friends" and multiple inheritance.

    But I've been doing PHP full time for nearly 8 years. I don't run into its quirks very often at all. Yes, it's happened, but I can't remember when was the last time I ran across a behavior that I had to stare at sideways for a while before going "oh, crap. PHP" 99.9% of my time is spend on known behaviors. Maybe that's because I've been working for the last 2 years on something I built and not those who came before me. I don't know. I do know I would beat someone with a clue stick for that line.

    But, you do realize that Javascript would behave the same way right?

    x.setValue(Boolean("wtf"));
    

    I think calling a constructor as a static function to create a Boolean object is way weirder than a dedicated casting operator, but that's just me.

    Python's bool("wtf") is the same.

    You can write bad code in any language.

  • (disco) in reply to HardwareGeek
    HardwareGeek:
    I don't PHP, but the same thing is true in Perl.

    "0" == 0; therefore, "0" is false.

    I've been using Perl for many years, and just discovered something I didn't quite expect.

    "0" really is special; it's not just being == 0 that makes it false. Other strings that evaluate to 0 in a numeric context nevertheless are true in a string context, despite being 0 in a numeric context.

    $ perl -e 'print "true\n" if ("0")'
    
    $ perl -e 'print "true\n" if ("0x0")'
    true
    $ perl -e 'print "true\n" if ("000")'
    true
    $ perl -e 'print "true\n" if ("0x0" == 0)'
    true
    $ perl -e 'print "true\n" if ("000" == 0)'
    true
    
  • (disco) in reply to jonnyq
    jonnyq:
    You can write bad code in any language.

    Yes. And here we see somebody not understanding the concepts, in a language with shifty concepts. Allow us to discuss both.

  • (disco) in reply to gleemonk
    php -r 'echo(0) or print(1);'
    

    Nobody tried my bonus WTF, did you? It prints 11.

  • (disco) in reply to gleemonk

    However, (int)(double)'3.2e1' != (int)'3.2e1'. Which is annoying if that's how your database insists on returning 32.

    Filed under: IHOC

  • (disco) in reply to gleemonk
    gleemonk:
    It prints 11.

    I would have had trouble guessing that print(1) returns 1, but otherwise that seems cromulent (and crazy).

  • (disco) in reply to gleemonk

    $foo = $bar or $preset is equivalent to ($foo = $bar) || $preset

    $foo = $bar || $preset is equivalent to $foo = ($bar or $preset)

    Other than their order of operation, they are exactly the same. You can have either behaviour, so just pick the operator that does what you want.

  • (disco) in reply to anotherusername
    anotherusername:
    You can have either behaviour, so just pick the operator that does what you want.

    and that's a defense of PHP, a language that ALREADY INCLUDES THE PARENTHESIS?!

    :wtf:

Leave a comment on “Truely Representative”

Log In or post as a guest

Replying to comment #453777:

« Return to Article