- 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
...$denominator = TRUE;
if ($denominator == 1 || $denominator == -1) ...
WTF?!!
Admin
Such a blasphemy. Everyone knows that dividing by zero results in a collapse of all known realities. Average to zero? That's the summary of our existance.
Captch: nobis - that PHP god is such a nobis.
Admin
At one time was the PHP God an accountant for the government? Or did he get his start massaging research results to justify grant money?
Admin
trwtf is religious belief
Admin
Finally, a way to safely_divideByZero(4.5, 0.0)
"PHP ERR -00425 division by zero"
Admin
The flowchart does not match the code.
Admin
Yospos, bitch. TBC forever.
Admin
According to the documentation this should been written as safely_divideByZero(4.5, "php")
Admin
PHP god? This guy needs to be sent to Hades.
Anyone who adds comments indicating how clever their code is, should usually be avoided, shot or buried naked and waist down in a red ant pit.
At the end of that cluster of dog piss that he calls a function, the only possible comment is "Whats the F'ing Point"?
If I saw this code, I'd crucify the coder, without burial so he won't rise again.
But then again, it is PHP, don't they all think they are gods...'wink'
Admin
Amusingly enough I once had a colleague who had to compute some ratio to be displayed as percentage. I asked him to throw IllegalArgumentException if the denominator was 0 but he decided to go another way, I think he didn't listen to what I said and tried to solve himself the case where the denominator was 0. He just replaced the denominator with 1 if it was 0 and wondered why the result sometimes was not between 0 and 100% but around one million %.
Admin
Unless I'm fundamentally misunderstanding PHP, surely the only code that will EVER run is the line:
$result = $numerator/$denominator;
...since if $denominator == "php" then it'll fail the second check and the line above just runs (in PHP $denominator can't both be equal to TRUE AND "php" can it?). Whereas if $denominator != "php" then it'll just run the above line of code again.
Surely this PHP God has an EPIC misunderstanding of how variables work.
Admin
Though I guess he got one thing right.
Any bad things are == "php".
Admin
And is also inconsistent by itself.
Admin
TRWTF:
Simply imagining the concept of dividing by zero didn't immediately make the guy need a quiet lie down.
Admin
Clearly you don't know PHP.
0 == "php" "php" == TRUE TRUE == 1
Admin
The RWTF regarding divide by zero is that people forget (or, more likely, were never taught) that division by zero does not indicate an arithmetic error. If you get into a situation where you are dividing by zero it means you have a model error, because division by zero indicates "your equation no longer provides useful information."
Checking the division operation is too late; if you have a divisor of zero that means you need to pick a different equation, not throw an exception.
Admin
I think (i'm no expert) that the $denominator variable, containing the string "php", will be implicitly cast to a boolean, and a string cast to a boolean results in 1.
Basically, the guy is relying on some rather shifty non-typesafe casting behaviour in php, that should probably be avoided at all costs.
Admin
The way it's supposed to work is that you throw an exception, and then something at a higher level of logic that knows how to handle it appropriately (for instance, by picking a different equation to try in this case) can do so.
Admin
PHP should basically be avoided at all costs.
Admin
Are you SURE the PHP God is a complete idiot? Isn't it possible that this code was intended as a joke?
Maybe he wrote it to confuse his replacement - or maybe because some manager, unhappy about complaints that customers got errors when they entered 0.0, ordered him to do a divide-by-zero function, and he did so in the most dumbly awkward way he knew?
CAPTCHA genitus - an attempt at genius which went wrong. Just like this code, perhaps.
Admin
What's all this "we" shit? I can guarantee that no one else was involved in this work of art.
Admin
This is quite possibly the most retarded piece of code I've seen on here in ages. I am at a loss for words.
Admin
Yeah that's what I was thinking - it seems a little too knowing/tongue in cheek to have been written by the complete idiot that the logic would suggest authored it.
Admin
I program in PHP professionally, and I suspect that a significant portion of the code was redacted to protect the incompetent.
The forced type coersion puts this in hell such that if there is a string that is equivilant to php, you climb all the way down the rabbit hole that will make any invocation of this routine to go down the -1 path.
Admin
I just realized that "php" is REALLY equal to 0 in PHP... and it is also equal to TRUE ! TRWTF is PHP...
Admin
Definitely a joke. This guy was just messing with anybody that actually looked at his code.
Admin
Historically, gods were seen as callous, uncaring, often unjust and their actions often appeared arbitrary or even downright malicious to mere mortals.
The traditional solution to such beings was to put their followers to fire and sword, tear down their temples and make enthusastic attempts to expunge their name from history. I feel this process has as much value today as it has done for thousands of years, and is a sadly underused business practise.
Admin
Aha, I think see what TRWTF is, it's right in the middle, where it suggests that the program flow goes back to "square one". There is no square one. But there's lots of round zeroes, which is what we are trying to avoid. So all we need to do is get the code to do to a square one and we're done. Am I right?
Admin
Took me a while to realize that the variable type of $denominator changed with each scope, hence why the assignment and the reason that we actually get a result. This would be redundancy to an ordinary programmer, but this "god" knew a few tricks about dynamic variables. Sad that he never learned programming ...
Admin
So basically this guy has just proven that 0 == 1. That, to me, is one brillant miracle.
Admin
Hey guys, I think I found a picture of the PHP God!
http://static.thehollywoodgossip.com/images/gallery/jared-lee-loughner-mug-shot_385x341.jpg
(In case you don't get the obscure joke: Loughner's public writings were chock full of constructions like this, "If you can create a new world currency, a new world currency is created. You can create a new world currency. A new world currency is created.")
Admin
Incorrect on the first one... I think the writer of the code was expecting someone to pass in the string "php" as the denominator value.
There are several languages where any non-empty string, or integer greater than 0, will evaluate to true. Strict type checking is required to differentiate. === vs ==.
These all evaluate to true:
0 != "php" "php" == true "php" !== true true == 1
All that said, the writers idiocy is not up for debate. This is some of the most appalling code I've ever seen in ANY language.
Admin
I think I'm going to have an aneurysm, just looking at that. PHP needs to die in a fire.
Admin
It's the royal plural.
Besides, it's more enterprisey. You're not just writing this for yourself. There's this huge corporation with its thousands of employees standing behind you on this.
If you're working for the government, 'we' is the entire $nationality people. How's that for awesome.
captcha: uxor - unsigned XOR. That's some advanced bit logic
Admin
All I can say to that is "OW!!!!". I think I'm having a stroke.
Admin
Hmmm ... you have a stroke if you like, I'm going to have a jolly good feel.
Admin
Admin
Anytime you have to explain a joke it's instantly a failure.
Admin
TRWTF is nobody here knows the correct solution to the problem,
Admin
This comment is clever.
Admin
The flowchart has the loop arrows for True/False inverted, and most if decisions are missing a "False" arrow.
Furthermore, I agree with David Wright and MC. This code is just a disingenuous demonstration of PHP type coercion rules.
Admin
Wow! This is the first one in quite some time that had me muttering "this guy is insane!" With a mind like that, how could he produce any code that worked? Ever?
The suggestion that this might have been a practical joke to confound mere mortals had me grasping at a glimmer of hope for a moment there. I thought maybe there is a future for the species after all. Then I realized, no, there isn't.
Props to one of the finer WTFs in a while. Like a fine wine. Which, of course, is just rotten grape juice that has been sitting around for a decade.
Admin
It's not unusual in technical writing, where "we" refers to "you and I, dear reader".
Admin
User: The application's not working.
boog: Yes, but sometimes it's working really well. You'll notice that these occurrences average out to mostly working, which is exactly what you were expecting. No need to thank me, just doing my job.
Admin
Just imagine him holding your hand walking you through a house of horrors, describing in excrutiating detail the thoughts going through his tortured and demented mind. Imagine a place so twisted that you can "cleverly" divide an apple amongst zero people...
Either that or he was just a moron with multiple personality disorder and was describing this for his "followers".
Admin
Actually
Admin
I divided by zero and all I got was this headache.
Admin
For someone who doesn't even know the language you're talking about, you do speak with a lot of authority.
Admin
I just correct my previous statement: We, in the office here, just tested that in PHP the integer 0, does indeed equal any string, but any (non empty) string also equals TRUE. An empty string also equals FALSE. It appears that PHP contains a rather large logical fallacy when it comes to these sorts of logical tests. In short, he could have used ANY string instead of "php" in the WTF function. I feel like a noob.
Admin