- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
setProcessing((boolean)'Frist')
Admin
It seems there was a need to pad that single line of code... Please reclassify as "ranticle".
Admin
Someone really needs to have a look at the CSS on the main site:
[image]Chrome 43.0.2357.125 (Linux.)
Admin
Best ad, would read again.
Admin
Blame bad handling of "float" CSS- fixed now.
Admin
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
is9
.Admin
"in fact the same as Perl"
I think you answered your own question.
Admin
Is there any reason at all for the assignment operators not to have the lowest precedence?
Admin
because PHP is special?
Admin
$v = my_function() or $v = "default";
is one reason for the lower precedence of "or"..... RTFM.
Admin
why would you want to write --> $v = my_function() or $v = "default"; instead of --> $v = my_function() or "default"; ??
Admin
If you stick stuff in
backticks
it will inline-format
your code so it's easier to differentiate it from the actual commentary...Admin
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:
Admin
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.Admin
C# invented the ?? operator ...
Admin
/me wonders if PHP is sane with its type coersion and
$foo = $bar || $preset
works correctly like it does in JS or not
Admin
JS is more relaxed here. PHP
||
coerces to boolean, so it only works right with flags.Admin
ah. so PHP really is TFWTF
Admin
Here is the code for a [fiddle][1]
The site wants me to register, and I'm much too lazy for that. [1]: http://phpfiddle.org/
Admin
wtf?
oh. no i got this. you left an accalia in your fiddle
still a :wtf: but this time it's PHP's WTF
Admin
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
Admin
BONUS WTF: Try guessing what this will print:
Hint: echo is not a function.
Admin
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.
Admin
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.
Admin
The inevitable FILE_NOT_FOUND comment.
Admin
Umm, yes. Yes I did. Totally intentional, just to test you. Not at all a copy/paste error. No sir/madam.
Admin
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.
Admin
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.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.
Admin
Has this ever been in doubt?
Admin
$dtRecord->setProcessing((boolean)'false');
would have been a more amusing WTF... at least as stated, the perpetrator can counter with "it works"
Admin
I was about to ask, does 'false' get type juggled into the boolean false?
Admin
No, any string, aside from the empty string and the string "0" would be converted to true.
Admin
Excellent! Why the string "0"? That seems a bit weird.
Admin
Admin
"0" == 0; therefore, "0" is false.
Admin
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.Admin
I don't think this is an argument that counts when talking about PHP...
Admin
I was talking from general principles :smile:
Admin
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.
Admin
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.
Admin
:hanzo:
Admin
Then PHP is not the language for you. (Neither is Perl.)
Admin
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?
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.
Admin
"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.
Admin
Yes. And here we see somebody not understanding the concepts, in a language with shifty concepts. Allow us to discuss both.
Admin
Nobody tried my bonus WTF, did you? It prints
11
.Admin
However,
(int)(double)'3.2e1' != (int)'3.2e1'
. Which is annoying if that's how your database insists on returning 32.Filed under: IHOC
Admin
I would have had trouble guessing that
print(1)
returns1
, but otherwise that seems cromulent (and crazy).Admin
$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.
Admin
and that's a defense of PHP, a language that ALREADY INCLUDES THE PARENTHESIS?!
:wtf: