• Simon (unregistered) in reply to Manadar
    Manadar:
    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.

    Except, of course, that you're adding extra code to allow for the case where everything that uses base64 is actually using your dodgy variant.

    But in practice, it's more likely that some of the cases are using the dodgy version, and some are using the real thing. In which case you're going to have to patch half the code to use different functions anyway.

  • Simon (unregistered) in reply to corroded
    corroded:
    having a wrapper for the function would have meant a single change rather than searching the entire code base for the method.

    Really? You'd just update that function and assume that everything works? You wouldn't go searching the entire code base, in case someone has used the PHP standard library function instead of your wrapper?

  • (cs) in reply to Daniil S.
    Daniil S.:
    Seriously, this is the very first time on WTF that everyone is actually agreeing with the perp. The world has gone mad!!!
    Actually, this sort of thing is quite normal on embedded systems where there is no filesystem.
  • Gaui (unregistered)

    I wouldn't call that WTF.. wrappers are often useful.

  • hardy (unregistered)

    The WTF-ness of this article is debatable.

    After all it is harmless, and some people just don't get it.

  • (cs) in reply to Norman D. Landing
    Norman D. Landing:
    dfgjh:
    you might still need the ol' Cntrl-F, but you'll only be replacing one instance not 567.834 of them

    Why would he need to fix that last 0.834 of them [/troll]

    Because that bit is throwing syntax errors?

  • (cs) in reply to Raniz
    Raniz:
    If you used split() you were either already using regular expressions or using the wrong method; explode() is the correct method to use if you don't need regular expressions.

    Besides, split() is merely deprecated (not removed), it echoes an E_DEPRECATION warning which should be shown on development servers and hidden on production servers.

    ...After PHP's developers spent a decade advising that if you're using split() then you're probably using the wrong function.

    Frankly, I think a number of PHP's developers are getting fed up with having to support ancient mistakes on the grounds that too many people would spit the dummy if the mistakes were corrected.

  • (cs) in reply to sino
    sino:
    There's only one base-64 encoding, dude. If you need something else, then don't fucking call it base-64.
    No, you call it base64url.
  • (cs) in reply to sino
    sino:
    rootkit:
    I haven't yet seen the right implementation, so I've just written my own. It follows some nice patterns and is, of course, easy to extend. The code is mostly self-documenting so I didn't bother to write elaborate comments. Have fun with it!
    <?php
    …
    ?>
    
    Please don't apply for jobs here.
    Yeah. It doesn't have nearly enough dynamism to be sufficiently Enterprise Ready. Perhaps if it was to fetch the list of functions to be wrapped at runtime it would be more ready for today's modern deployment environment. I'm in two minds whether that list ought to be in a database or on another webservice…

    Or maybe we could hold the function mapping in a 3rd-party ontology repository. Yeah, that would multiply the amount of crazy appropriately.

  • Henk Henkerton (unregistered) in reply to MB
    MB:
    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...

    Not to mention inconsistently.

  • (cs)

    all I see in code is a wrapper for function that exist previously. who has not done this in programing life? i bet all of us are guilty at one point or another.

  • (cs) in reply to Henk Henkerton
    Henk Henkerton:
    MB:
    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...

    Not to mention inconsistently.

    Better still, a function base64Encode with a second parameter "forward", e.g.

    function base64Encode($str, $forward = true) {
      return $forward ? base64_encode($str) : base64_decode($str);
    }
    

    I've omitted the obvious bloat that should be added to increase the SLOC significantly (e.g. like the code I've posted earlier).

    Maybe the $forward parameter should be set to false by default. Just to spice things up a little.

  • Regex (unregistered) in reply to Rootbeer
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^\d+$/ problems.
    I prefer this version, since it matches... "Now they have 0 problems".
  • Willy Loman (unregistered) in reply to Stir Pot
    Stir Pot:
    Martin D:
    A comment on every line is not "well commented" code.
    Depends on how you define well.... Well Commented might mean good commenting Well Commented might mean liberally commented Well Commented might mean well, commented Well COmmented might mean commented with waterhole references...

    etc...

    There's a difference between well commented and well commented

    Is that anything like being liked, but not well-liked?

  • Al (unregistered)

    How do people not think that this is a WTF?

    Nothing like coding or designing for problems that may or may not exist in the future. I'm in full agreement with the comment that has the world spinning function.

    Create for wrapper after the depreciation. Sure you may have have to do a large number of swaps but that is dothing compared to wrapping every funtion (and remembering to use the correct wrapper every time).

  • corroded (unregistered) in reply to Coyne
    Coyne:
    I especially like the wasteful coding of the interior of the functions. Three lines when (even assuming a wrapper was justifiable) this would have done for base64Encode:
    function base64Encode($plain) {
      return base64_encode($plain);
    }
    
    Especially the initialization of $output, which was immediately overwritten, demonstrates a desperate lack of understanding of coding principles.

    Actually in PHP it's not entirely a bad idea... the problem being that register_globals, that old chesnut of evil, had variables magically appearing as if from nowhere, and with data in them.

    Now admittedly, I'd have returned directly instead of mapping to a variable.

    Interestingly, assignment via a ternary operator is slower than defaulting a variable, then doing a check for correct data, then assigning the variable if there is some. It might be 4 times the amount of code, but from a performance standpoint it wins.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered) in reply to geoffrey, MCP, PMP
    geoffrey:
    I would do it like this:

    function detectEarthStatusWrapper(){ //May need to add code in the future return detectEarthStatus(); }

    function detectEarthStatus() { return true; }

    Absolutely! Because what if someone wants to use that code for a Mars mission?

  • Is that a suppository up my ass or are you just happy to see me? (unregistered) in reply to Willy Loman
    Willy Loman:
    Stir Pot:
    Martin D:
    A comment on every line is not "well commented" code.
    Depends on how you define well.... Well Commented might mean good commenting Well Commented might mean liberally commented Well Commented might mean well, commented Well COmmented might mean commented with waterhole references...

    etc...

    There's a difference between well commented and well commented

    Is that anything like being liked, but not well-liked?
    Or Like-Like's for that matter?

    Shield-stealing piles of shit!

  • (cs) in reply to sino
    sino:
    There's only one base-64 encoding, dude. If you need something else, then don't fucking call it base-64.

    And which is the One True Base64? The one originally formalized by RFC 989 (now deprecated), its revised form as found in RFC 1421, or one of the variants described in current RFCs 2045, 3548, or 4648?

    Or one of a dozen other ad-hoc variants on the scheme that are also in common use?

    (For what it's worth, PHP's native implementation is of the MIME variant from RFC 2045.)

  • Anon (unregistered) in reply to Regex
    Regex:
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^\d+$/ problems.
    I prefer this version, since it matches... "Now they have 0 problems".

    You are correct

    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^[1-9]+\d*$ problems.

    Fixed?

  • rnelson0 (unregistered) in reply to hardy
    hardy:
    The WTF-ness of this article is debatable.

    After all it is harmless, and some people just don't get it.

    Are you planning to hire people and train them on the useless wrappers, and then exert additional effort ensuring that they never use the native function names? That sounds harmful to me.

  • TheJonB (unregistered) in reply to Anon
    Anon:
    Regex:
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^\d+$/ problems.
    I prefer this version, since it matches... "Now they have 0 problems".

    You are correct

    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^[1-9]+\d*$ problems.

    Fixed?

    At least they can't have 10 problems.

  • (cs) in reply to TheJonB
    TheJonB:
    Anon:
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^[1-9]+\d*$ problems.

    Fixed?

    At least they can't have 10 problems.

    They can, check again. But a less ambiguous version of the regex would be

    /^[1-9]\d*$/

  • Ben Jammin (unregistered) in reply to rootkit
    rootkit:
    TheJonB:
    Anon:
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^[1-9]+\d*$ problems.

    Fixed?

    At least they can't have 10 problems.

    They can, check again. But a less ambiguous version of the regex would be

    /^[1-9]\d*$/

    I think this conversation just goes to show why the "Now they have 2 problems" quote exists.

  • Anon (unregistered) in reply to rootkit
    rootkit:
    TheJonB:
    Anon:
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^[1-9]+\d*$ problems.

    Fixed?

    At least they can't have 10 problems.

    They can, check again. But a less ambiguous version of the regex would be

    /^[1-9]\d*$/

    Sssshhh. That extra + was a trap for people who only think they know regex.

  • Zun Zun Zuuun (unregistered) in reply to Willy Loman
    Willy Loman:
    Stir Pot:
    Martin D:
    A comment on every line is not "well commented" code.
    Depends on how you define well.... Well Commented might mean good commenting Well Commented might mean liberally commented Well Commented might mean well, commented Well COmmented might mean commented with waterhole references...

    etc...

    There's a difference between well commented and well commented

    Is that anything like being licked, but not well-licked?
    ZTFY

  • qbolec (unregistered)

    Actually I had to do similar thing in my project: I wrapped several built-in functions into a singleton class which I called Builtins.

    The reason was I wanted to write unit tests, which is quite difficult with PHPUnit which does not allow you to mock library functions.

    Eventually we found some different project which claimed to be able to mock global functions, but it also didn't alow to mess with builtins.

    We also tried runkit library, and ... well, do I have to justify that? Actually I'd rather here "designers" of PHP language why did they put all these unreleated functions with different conventions and purposes into single global scope. Of course the quick answer is: because namespaces and Objects were introduced several years after PHP was born. But the real question is: how come that in the XXI century someone created a language which is not object oriented (nor functional, nor modular, nor ...)..

  • geoffrey, MCP, PMP (unregistered) in reply to qbolec
    qbolec:
    Actually I had to do similar thing in my project: I wrapped several built-in functions into a singleton class which I called Builtins.

    The reason was I wanted to write unit tests, which is quite difficult with PHPUnit which does not allow you to mock library functions.

    Eventually we found some different project which claimed to be able to mock global functions, but it also didn't alow to mess with builtins.

    We also tried runkit library, and ... well, do I have to justify that? Actually I'd rather here "designers" of PHP language why did they put all these unreleated functions with different conventions and purposes into single global scope. Of course the quick answer is: because namespaces and Objects were introduced several years after PHP was born. But the real question is: how come that in the XXI century someone created a language which is not object oriented (nor functional, nor modular, nor ...)..

    Shhhh. Your reasoning is ruining the fun of everyone who ragged on me for thinking this is not a WTF.

  • (cs) in reply to Willy Loman
    Willy Loman:
    Stir Pot:
    Martin D:
    A comment on every line is not "well commented" code.
    Depends on how you define well.... Well Commented might mean good commenting Well Commented might mean liberally commented Well Commented might mean well, commented Well COmmented might mean commented with waterhole references...

    etc...

    There's a difference between well commented and well commented

    Is that anything like being liked, but not well-liked?
    More as in: steak that's well done is inedibly burnt.

    Or: if Matt Westwood gives geoffrey or Bob's retard son a "good kicking", from the point of view of both the victims the outcome is far from good ...

  • MAnuel (unregistered)

    Why no complains about no new article yet?

    Maybe here needs change name to NotNecerilyDailyWTF.com

  • Jay (unregistered) in reply to bart
    bart:
    Agreed.

    I am often shocked at those that are quick to judge.

    Who are you to criticize me for being judgemental? That's very intolerant of you. If I want to be judgemental, that's just how I am.

  • Jay (unregistered)

    Yes, creating wrappers for functions to implement a naming convention that you prefer to the one used by the library authors is a great idea! It improves readability and consistency.

    But ... what if some members of your staff have different preferences for naming conventoins? What the programmer should really have done is made several sets of wrappers, one for each naming style he could think of. Like:

    function base64Encode { ... }
    function Base64Encode { ... }
    function base_64_encode { ... }
    function strBase64Encode { ... }
    function str_base_64_encode { ... }
    

    Then everyone can use their favorite naming convention and everything works! Plus, if Al wants to use a different encoding function than Sally, he can just pick one of parallel functions and change the implementation.

  • Jay (unregistered) in reply to fritters
    fritters:
    Ronan:
    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; }

    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!

    And of course, the XML file should be stored on a different computer, and you create a SOAP interface to communicate with it, so that if there are changes, you don't even have to modify data on the production server!

    I would quibble that creating the XML from an Excel spreadsheet is not very enterprisey. You really should generate it from a UML diagram.

    captcha: "aptent" A temporary canvas building used to store application install CDs.

  • vulputate (unregistered)

    I wonder WhyTF I keep coming here. This is the 3rd time today that I peeked hoping I would find my fcuking DAILY serving of WTF article, and not a fcuking thing. Alex, you suck.

  • Jay (unregistered)

    By the way, tangential to debating the wisdom of the coding style, but: "seemingly a nice guy at first, but really just a phony"

    So ... "I thought he was a nice person, but it turned out that he really wrote poor PHP code." How does that make him a "phony"? Do you mean that "nice guys" always write good PHP code? That people who write bad PHP are inherently rude?

    I thought this was a web site about bad programming, but it turns out it really has a gray background.

  • Ben Jammin (unregistered) in reply to Jay

    Nice guys are considerate of others. By writing PHP code, (I'll assume you were attempting humor with "good PHP") a person is perpetuating a tool of torment to those who must follow them in maintaining whatever code base they've created. Therefore, yes, people who write PHP (I'll assume you were just being redundant with "bad PHP") are inherently rude.

  • Tud (unregistered) in reply to Jay
    Jay:
    Yes, creating wrappers for functions to implement a naming convention that you prefer to the one used by the library authors is a great idea! ...
    THE WHOLE POINT IS THAT THERE IS NO NAMING CONVENTION USED BY THE LIBRARY AUTHORS.

    I WISH I COULD MAKE THIS TEXT BIGGER.

  • (cs) in reply to vulputate
    vulputate:
    I wonder WhyTF I keep coming here. This is the 3rd time today that I peeked hoping I would find my fcuking DAILY serving of WTF article, and not a fcuking thing. Alex, you suck.
    Quick! Call the waaambulance! We've had another outbreak of ingratum quae sunt gratis ("ingratitude for things that are free of charge")!
  • (cs) in reply to Jay
    Jay:
    Yes, creating wrappers for functions to implement a naming convention that you prefer to the one used by the library authors is a great idea! It improves readability and consistency.

    Internally, yes.

    But in another way, your code is now LESS consistent, because you're now using a different name for the function than the rest of the PHP-writing world, including language references like php.net.

  • Nagesh (unregistered)

    It seems to have gone unmentioned that the predecessor chose to call the formal parameter to his base64Decode ..

    $scrambled
    ?

    Methinks he didn't quite understand what base64 is for, even.

  • Jonathon (unregistered)

    This is pointless. Anyone can sed -i through the code and replace it in the future if for some reason they need to.

  • Joey (unregistered) in reply to sino

    PHP -- In the upgrade to 5 they made array_merge require both paramaters to be arrays, instead of automatically converting as it had previously. I had the job of going through our codebase on my project and changing array_merge( $param1, $param2 ) to array_merge( (array)$param1, $param2 ) in the cases where $param could have been something besides an array.

  • capio (unregistered) in reply to Silverhill
    Silverhill:
    vulputate:
    I wonder WhyTF I keep coming here. This is the 3rd time today that I peeked hoping I would find my fcuking DAILY serving of WTF article, and not a fcuking thing. Alex, you suck.
    Quick! Call the waaambulance! We've had another outbreak of ingratum quae sunt gratis ("ingratitude for things that are free of charge")!

    Listen, dick... this site makes money off of my coming here. I expect to be paid in fucking articles that are published as frequently as suggested by site name. If he doesn't make money running this, then shut it the fuck down: he obviously lost enthusiasm finding and publishing stories, cause they such big time lately.

  • capio (unregistered) in reply to capio
    capio:
    Silverhill:
    vulputate:
    I wonder WhyTF I keep coming here. This is the 3rd time today that I peeked hoping I would find my fcuking DAILY serving of WTF article, and not a fcuking thing. Alex, you suck.
    Quick! Call the waaambulance! We've had another outbreak of ingratum quae sunt gratis ("ingratitude for things that are free of charge")!

    Listen, dick... this site makes money off of my coming here. I expect to be paid in fucking articles that are published as frequently as suggested by site name. If he doesn't make money running this, then shut it the fuck down: he obviously lost enthusiasm finding and publishing stories, cause they such big time lately.

    SUCH = SUCK

  • PHP Freak (unregistered) in reply to Ronan
    Ronan:
    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...

    Man you did not finished your PHP lessons, do you ?

    PHP natively supports variadic arguments, see the doc for func_get_args().

    And by the way, what you are writing already exists, is called http://php.net/manual/en/function.call-user-func.php

    "Calls the callback given by the first parameter and passes the remaining parameters as arguments."

    Do not even attempt to beat PHP weirdnes ... you won't be able to.

    PHP implements all your WTFs natively.

    "All your WTFs are belong to us", is the new PHP5 motto. Ever heard of "variable variables" ?

  • LOADING (unregistered) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Tractor:
    Anon:
    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.

    Agreed, this is actually quite a sane thing to do. It keeps the function names consistent, god knows the PHP developers didn't.

    And you know a language is really bad when even the trolls about it raise good points.

    The inconsistent naming is something you just have to get used to. PHP wraps a lot of C and C++, some of it probably comes from there.

    Wrapping base64 seems a bit pointless. I have wrapped things before, occasionally misguided but usually fruitful. For example, you wouldn't want to not wrap the mail() function with your own.

  • Mr. Caulfield. (unregistered) in reply to frits
    frits:
    Seriously guys, what software dev isn't a phony?
    Please, show some sensitivity. I had a son once who was a phony, and let me tell you, it's no laughing matter.
  • (cs) in reply to Tud
    Tud:
    Jay:
    Yes, creating wrappers for functions to implement a naming convention that you prefer to the one used by the library authors is a great idea! ...
    THE WHOLE POINT IS THAT THERE IS NO NAMING CONVENTION USED BY THE LIBRARY AUTHORS.

    I WISH I COULD MAKE THIS TEXT BIGGER.

    YWIMCTFY.
  • Regex (unregistered) in reply to Ben Jammin
    Ben Jammin:
    rootkit:
    TheJonB:
    Anon:
    Rootbeer:
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have /^[1-9]+\d*$ problems.

    Fixed?

    At least they can't have 10 problems.

    They can, check again. But a less ambiguous version of the regex would be

    /^[1-9]\d*$/

    I think this conversation just goes to show why the "Now they have 2 problems" quote exists.

    Argument is based on a false predicate: If the person doesn't understand regular expressions, then they already had more than 1 problem to start with. :)

  • xyz (unregistered) in reply to Mikey

    omg you are so hilarious

    get a life... for real

Leave a comment on “The Phony”

Log In or post as a guest

Replying to comment #:

« Return to Article