- 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
/* Frist function ** ** Just for consistency and ** ease of maintenance, let's declare our own function **/ function frist() {
// Initialise output variable $output = "frist";
// output the output echo $output; }
Admin
Frist - and not SPAM
Admin
Did he reimplement PHP in the end?
Admin
Frist?
Akismet thinks this is spam. It probably is.
Admin
Damn you Akismet. Three other comments while I battled you.
Admin
You're a phony
Askimet is a phony too.
Admin
That's... somewhat pointless but not totally stupid.
PHP is a notorious mess, and he's trying to build an abstraction layer on top of it. To improve the tool, really. It's the same thing framework developers are trying to do, just on a much smaller scale.
Admin
I had a coworker who wanted to wrap everything. Our company has a set of common shared libraries for common functions. My coworker thought we should wrapper any calls to the company's common libraries from our project in our project's own utility functions. That way, if our company's internal software (our project) was ever moved to another company, it would be easy to swap in a different library.
Admin
And in the end it turns out they actually needed a variant of base64. The new programmer only has to edit those two functions with the correct implementation.
That's sometimes how those things work out. If you suspect your implementation of base64 is not what PHP offers, please please please, do something like this. Even if that means your implementation of base64 is not base64.
Admin
He should have made it generic.
function call_php_function($function, $parameter){ //Initialisation of return value $return_value = '';
//Call of the php function $return_value = $function($parameter);
//let's return te result return $return_value; }
of course, you'd have to do that multiple times to account for the number of parameters for different php function. function call_php_function_1_parameter($function, $parameter) function call_php_function_2_parameters($function, $parameter1, $parameter2) etc...
Admin
Looks like he wrapped the function to make it easier to fix if php updates end up changing the name or the method of calling it. Seems pretty standard to me. #ifdefs do this ALL THE TIME in C/C++ code to handle differences in compiler and architecture.
Admin
It's a good start but not enough - what if his interface changes? Sure, he says it's for ease of maintenance but you can't trust other people.
Thus my solution to this WTF:
<?php /* Base 64 Encoding function ** ** For even more consistency and ** ease of maintenance, let's declare ** a wrapper around our base64Encode. ** ** Allows for partial refactoring and other ** enhancements if needed in the future. **/ function base64EncodeWrapper($plain) { // Initialise output variable $output = ""; // Do encoding $output = base64Encode($plain); // Return the result return $output; } /* Base 64 decoding function ** ** For even more consistency and ** ease of maintenance, let's declare ** a wrapper around our base64Encode. ** ** Allows for partial refactoring and other ** enhancements if needed in the future. **/ function base64DecodeWrapper($scrambled) { // Initialise output variable $output = ""; // Do encoding $output = base64Decode($scrambled); // Return the result return $output; } ?>Admin
This is not a WTF, if this is what a WTF looks like for you, then you are lucky, a true WTF would be him implementing his own base64decode / encode, each time, everywhere, incorrectly...
Admin
So wrapped the native function in a CamelCase name. Sounds sensible to me. And he even commented it with sort of that explanation!
Admin
seems like a great way to fix deprecated methods in the future....
Admin
I can respect the intent to apply some consistency to the calling conventions for PHP's internal functions: some are underline_separated, some are camelCased, some lead with the subject, some with the verb, and no two functions that take haystack and needle parameters take them in the same order.
These new function definitions still aren't very good, though. The code's needlessly explicit in a way that makes me believe the coder doesn't understand how 'return' works, and the comments are completely useless.
Admin
Agreed, this is actually quite a sane thing to do. It keeps the function names consistent, god knows the PHP developers didn't.
Admin
Admin
Bingo. I've seen a sysadmin trawling through code to fix PHP removing a method that was used throughout the system. Now, admittedly he shouldn't have upgraded PHP without checking better... but having a wrapper for the function would have meant a single change rather than searching the entire code base for the method.
Admin
Admin
I applaud this guy for not using any magic functions.
Admin
Wrong and wrong again.
Admin
Admin
I resent that. I've never raised a good point in my life.
Admin
Clean code, new shoes And I don't know where I am goin' to.
Standard functions wrapped tight,
I dont need a reason why
They leave running just as fast as they can. Cause every manager's crazy bout a sharp dressed man.
Admin
Admin
You should at least break backwards compatibility with PHP4 by using type hinting. We have to move on!
Similis: A mixture of an illness and a smiling doctor.
Admin
Tsk, that's not enterprisey enough... and you can do it without duplicating function calls.
function evil($function) { $args = func_get_args(); unset($args[0]); //removes function name
}
echo evil('echo','lies'); //lies echo evil('echo',3+3); //6 echo evil('echo','3+3'); //3+3
I apologise in advance for the current vomit coming out of your face.
Admin
No. The better way is to set up a mapping using an Excel spreadsheet, then generate an XML configuration file.
Then your code just needs to parse the XML file and follow the translations. This way if you ever need to change them or add more, you don't even have to make code changes!
It's brillant!
Admin
Do not speak aloud of enterprisey PHP. By doing so, you could accidentally call up that which you cannot put back down. Some elder horrors must be left to slumber undisturbed.
Admin
So, you've basically just described Java.
Admin
Admin
In any other programming language this would definitely be a WTF but seen as it's PHP he's actually adding value by standardising the naming convention.
<?wtf echo "the real WTF is PHP"; ?>Admin
Java, and C++ before it, are compiled languages so that performance can be optimized. Modern compilers can fold the wrappers as in-line code, and C++ has a qualifier for that.
Also, Moore's Law is far less important than properly using the CPU's instruction set. Computers will change speed, materials and architecture that interpreters and compilers have to suit.
Admin
Seriously, this is the very first time on WTF that everyone is actually agreeing with the perp. The world has gone mad!!!
Admin
Ontopic: while I hate to admit it, PHP's own naming conventions are non-existent at best, and deliberately confusing at worst. I do not condone writing code for the sake of writing code either, but this is not necessarily a bad idea. I have seen far, far worse PHP.
Admin
Even if the wrapper function is neccessary, the number of lines isn't. It could surely be shortened to
Admin
Just what PHP needs: Perl like functions.
Admin
Nah, just the first time all commenters are trolls. BTW, I agree with the perp.
Admin
Seriously guys, what software dev isn't a phony?
Admin
$meToo++;
Seriously, whose kneecaps do I break for DEPRECATING split()? I'm a little surprised that Rasmus made it out of Penguicon with all his extremities a couple of years back. Anyone starting a new project in PHP in this day and age is either drunk or mismanaged.
Admin
Agreed.
I am often shocked at those that are quick to judge.
Admin
Admin
Everything must be wrapped (also wrappers, if possible)
Every variable must be initialized (even if the first thing you do with it is set it)
Never do two things in one line/statement (not even a function call and return)
Every line must be commented (even if self-explanatory)
And that's just the start. The other 42000 rules get really absurd.
(Yeah, would be more funny if it weren't so common.)
Admin
There is no programming problem that can't be solved by adding another level of indirection, except of course, too many levels of indirection.
Admin
Worse, because in php, you can make "just-in-case wrappers" by just doing:
base64Encode = base64_encode
Not like making wrappers for each php function before it gets changed is quite unnecessary. Regardless of the mess fanboys call php to be.
Admin
Shit! Didn't know this. Haven't touched PHP with a pole since version 3 and believe me, I'm not turning back.
Anyway, if anyone thinks this is a good idea, it's because we're talking about PHP here people. In any other sane language you wouldn't have to worry about lossing base64... shit, Java have had Vector deprecated for 20 years but you can still use it.
Admin
I'm pretty sure if you create enough indirection, you summon Cthulu, or create a black hole, in which case you've solved every problem on Earth.
Admin
What's that old chestnut? Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.
Admin
somebody has some $plain-in' to do!