- 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
Okay, so I realize I'm not a PHP Pro. But I consider myself somewhere around the top of the bell curve, if not slightly in front based on experience alone. So when I was trying to trace those functions, I going nuts. I was really having trouble understanding the purpose.
Then I read the last line about using $_GET, $_POST, etc, and realized why I was having trouble. With globals like $_GET and so on, I never once considered doing it any differently.
So I learned two things from this article:
When trying to trace another person's script, it's best to ignore all logic and reason (a lesson easily learned from any WTF here).
Thought it's really useless to know in practice, I now know an alternative to $_GET and $_POST. But I'm going to make a conscious effort to forget the alternative as soon as I'm done this post.
Yay for learning.
(PS - this is the first time I've read CodeSOD because PHP and Perl are the only languages I know. There should be sub-categories for CodeSOD so that I can see what the language is at a glance).
Admin
With operator overloading catching on, this function seems like a good idea.
Admin
the truth function is buggy should have been :
Admin
In principle the queryStringToArray() is not such a horrible thing. The crime is not using prarse_str() for this. Although sometimes you may want your own function to behave slightly differently or do less with better performance.
Admin
Hmmmm.
Shit. I knew this was a bad time to start programming in PHP.
Admin
The == and >= operators are used far too often. Here is an "Enhancement":
function MatchField($field, $cond, $value) { if ($cond == '==') return $field == $value;
}
Admin
I think it's optimistic that he finds truth in everything but no, false, & off. That's very open-minded.
Admin
"1" is a macro that uses a SOAP call to GetCurrentConstantValues() on the Sunfire.
Admin
Of course, i started immediately to search whole my code about logic like these. Of course, I will not show here the search result :D, it's a shame for me, but instead I taken a long vacation to rewrite all my code to be ready for revolutionary changes such as definning function =2+)( when equal meaning adding in reverse mode to the to objects initialization like US$ = old Eur(paramsurgeon). So hold on forever. The bugs and new crazy ideas it's the most old species from the world.
Admin
I was rather hoping that it would be expressed through an embedded lisp interpreter, like so:
Absolutely no side-effects or assumptions whatsoever. It's magic!
Admin
Thanks for mentioning one way to produce memory leaks in language runtimes with reference-counting pointers - circular references. There are of course many more, and most others also affect runtimes with marking gc algorithms such as keeping too many references in globally scoped containers or forgetting to explicitely unregister observers. I've seen many memory leaks caused by these issues in both Java and .NET. (Java is at least smart enough to use WeakReferences for its own event handling - this can in turn cause objects to be collected prematurely but that's arguably the lesser problem.)
Garbage collection prevents memory leaks by freeing objects that are no longer needed, right? Wrong, you fscking retard! Garbage collection frees objects that are no longer referenced rsp. reachable from the stack and static variables. Modern filesystems do not keep unreachable data around either, so why's your hard disk always full? Because you are keeping a lot of references to data that you no longer need, that's why.
There's nothing wrong with garbage collection (although it's rarely necessary in modern C++), but there's something seriously wrong with all the Java/PHP zombies who think gc solves all memory problems and then go on to write the most incredibly resource hogging PoS applications ever to roam the Internet.
Oh, and by the way, C++ has had reference-counting smart pointers for a long time, e.g. boost::shared_ptr. And those are actually a lot more versatile than anything PHP has come up with so far.
The word you are looking for is "inlining", something that C and C++ compilers (and even some linkers) have supported for a long time as well. And, by the way, isn't it rather ironic to mention PHP and good compilers in one sentence? I'm not saying that there couldn't be a good compiler for PHP in theory. But in practice, there isn't. PHP is still dog slow compared to "bare metal" languages like C/C++.
Admin
It'll break earlier then that, namely when when long var is gone.
So I guess we'll get many other laughters before they change the syntax for '<
Admin
Admin
Quick question from someone who found TDWTF recently, why the railing against PHP? I'm not defending it necessarily, just wondering why.
Admin
Its a tetrahedron?
Admin
Kuba is perfectly correct to state that "in principle" (his words) a PHP interpreter/compiler/magic box could optimise/inline this code. That's just the start, in fact; I refer you to Steve Yegge's latest post for other interesting possibilities. "In principle" is good enough. You expect him to go away and rewrite PHP5 just to prove his point? Gee, you're a hard task-master.
Dog-slow isn't necessarily important. Pig-ugly is, as far as I'm concerned. Many people (not I) would claim that C and C++ fit this description just as well as PHP does.
I used to get all steamed up about this fetish people have for garbage collection. "What's the big deal?" I cried. "Where's the determinism?" I moaned. "Memory isn't the only resource you can leak," I whined, "and it's not even the most important one."
Well, I still think I was right, but I'm interested in the second generation of language support for gc. And no, I'm not talking about "generational garbage collectors," because they're not part of the language support. I'm talking about:
(1) Strong references (2) Weak references (3) Soft references (4) Phantom references
Excuse me, but wasn't the whole idea of gc that it takes all the pain of thinking about this stuff away from the programmer? What's the point of a promise like that if we're all forced to deal with arbitrary abstractions, rather than something concrete and intelligible like RAII and Boost smart pointers?
I'm obviously missing something here.
Admin
It lacks a FILE_NOT_FOUND statement...
Admin
PHP is kind of like a language where someone actually tried to break every convention and standard practice possible.
Admin
queryStringToArray... not so weird.
Yes, there's a built-in function for it, but PHP has so many of the damned things that it's quite easy to miss them.
That implementation isn't that bad either - pretty typical of newbie PHP developers, using just the basic builtins. He forgot about URL encoding though, and I can't work out what $GL_strlen and $GL_strpos are for.
Disclaimer: I've written a function similar to that, working on similar principles, except without the $GL_ crap, and passing everything through urldecode after it was split up.
As for it's use... I only needed it because I was extracting information from URLs which were in turn extracted from HTML files, and replaced that with parse_url once I found out about it.
I can think of no use for it in a typical web app though.
Admin
Admin
Trust me, there were no server-side includes. This is strictly bad coding.
Admin
And that, ladies and gentlemen, gets my vote for best comment on this post.
Admin
Years later we will look back on the original coder as a visionary. That last function had me in tears (tears of joy, and dismay).
Admin
Googling for PHP compiler reveals that there actually are native PHP compilers. If you used one of those, counting native machine instructions could sometimes be even justified, if you were trying to do something performance critical... in PHP.
Admin
You could just as well rewrite the + operator, couldn't you?
(C# code)
public int Add(int a, int b) { int result = a; for(int i = 0; i < b; i++) { result = result + 1; } return result; }
Admin
I have it on good authority that next version of PHP will replace "=" with "CANHAS".
Admin
Further evidence that some people should not be permitted near a computer at any price. You don't suppose that he used some tutorial and recreated methods that were designed to "test" php features so that a noob can figure out wtf (s)he is doing do you?
CAPTCHA: transverbero => it is the frequent boosts to my vocabulary that prevent me from using my login!
Admin
what do you know... a wtf on the wtf site. ...
DIE SPAMMER!
Captcha: oppeto ... the sound a VW bug makes in a tunnel... ?
Admin
Actually, I'm looking forward to PHP7 and the inevitable replacement of "===" with "Its_alreadyStored_inMemory_As_aString_comma_dimwit_WhatPartof_comparison_DontYou_Understand_query"
Admin
Admin
Nevertheless: what if they change the semantics of the function call???????????
Admin
I'm sooooo hoping you are making a joke Chucara...
Admin
I have another one: I had to help a customer extend and improve a GUI for an industry robot arm. The stuff was written in C# (luckily my last excursion into MS land) and the developer at the customer site held a degree in CS, as far as I remember, but he couldn't program his way out of a paper bag. My favorite function from him is this (no, I'm not making this up):
There were more of these "gems", and I was quickly able to improve the speed and responsiveness of this application dramatically. What I found really frightening was the fact that this guy was also responsible for the robot arms' firmware !