• (cs) in reply to PHP Freak
    PHP Freak:
    PHP implements all your WTFs natively.

    We know. That's more or less the rationale behind the language.

  • corroded (unregistered) in reply to PHP Freak
    PHP Freak:
    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" ?

    That's why I modified his code to use func_get_args, and used variable variables. It's way more WTFey they using call_user_func.

    As an additional WTF, in PHP you can't create a variable with a number at the start. However, in a variable variable, you can.... oh, and not then be able to reference it. Unless you write something that uses a variable variable as a reference. I wish I was making that up.

    $var = 1; $$var = 'test'; echo $1; //parse error echo $$var; //test

  • ted (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.

    This. This. A thousand times this. It's not fucking clever.

  • Cabbage (unregistered)

    Just to point out, this exists within the SagePay integration examples along with a whole lotta other wtf.

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

    Ahem... I totally misread that...

    oh the shame

    sob

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

    $ cd project $ tar -cxf ../project_backup.tgz . $ for thing in find . -type f -name "*.[pP][hH][pP]"; do cat $thing | sed "s/oldfn/newfn/g" > $thing.longer;mv $thing.longer $thing;done $ cd .. $ mkdir compare $ cd compare $ tar -xpf ../project_backup.tgz $ diff -r project ../project

    ^---or similar should do it. (The regex may need a bit of tuning.)

    Any decent IDE worth it's salt (or eclipse if you must) will do a similar kind of search and replace.

    Learn to use tools properly and extra function calls really aren't needed.

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

    This. This. A thousand times this. It's not fucking clever.

    We've got some great companies that sponsor The Daily WTF. And all they ask in return... just take a moment or two to check out what they do. It's some pretty cool stuff.

    http://thedailywtf.com/Articles/Sponsor-Appreciation,-High-Tech-in-Arkansas,-License-to-Enumerate,-and-More.aspx

  • Jay (unregistered) in reply to Ben Jammin
    Ben Jammin:
    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.

    Good point. Thanks for clearing that up for me.

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

    Please to reset your sarcasm detector.

  • Meep (unregistered) in reply to Manadar

    "And in the end it turns out they actually needed a variant of base64. "

    Been there, done that. The correct thing to do, though, is to give it a generic name rather than citing a standard that you're not adhering to.

  • Jay (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.

    Oh, all right. I would like to introduce a motion that we withdraw the armed guards who force this poor gentlemen to visit this site three times day, and that we discontinue the beatings and torture when he fails to do so.

  • Aran (unregistered) in reply to Anon
    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.

    There are definitely reasons to wrap functions in PHP. For example, the Drupal CMS wraps all string functions to add fall-back multibyte handling in environments that have no mb extension installed.

    But if an abstraction layer doesn't do anything, then it is a stupid programming error as it makes a program slower, larger and less maintainable for no benefit. The notorious mess is not PHP, but the result of developers like this using it.

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

    Yes, variables do need to be initialized, especially in a world of register_globals. But this doesn't make sense in any world:

       $output = "";
       $output = "foo bar";
    

    Even if the first line is omitted, the second line ensures that any prior value of $output is overwritten.

    Now go see the original code snip: Just doesn't make sense, does it?

    Addendum (2012-02-25 17:44): Oh, and by the way: Why even have $output when you can return the value directly, as in my example?

  • (cs) in reply to foo

    You have got to keep the code slow, otherwise people will stop wanting to upgrade their hardware. If this were not the case, why would .NET exist?

  • (cs) in reply to foo
    foo:
    corroded:
    steve:
    seems like a great way to fix deprecated methods in the future....

    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.

    By the logic, why not wrap everything, functions, variables, constants, files, networks, character sets, just everything. Anything might change some day, after all, and spending some effort to adjust later is certainly worse that spending 10 times the effort now. Fuck performance, Moore's Law will take care of that, right?
    You must keep the code slow with matryoshka abstraction, otherwise folk will stop upgrading their hardware, and the sillicon sky will fall. If this were not the case, why would .NET exist?

  • gabs (unregistered)

    actually this wouldn't be so much of a WTF if this guy made an encryption class to wrap all encryption methods in it for coding speed/maintenance like: $wtf0 = PhonyEncryption::base64Encode("usitas (askimet)"); $wtf1 = PhonyEncryption::rijndael256Encode("usitas", $key);

  • facilisis (unregistered) in reply to Shagen
    Shagen:
    You have got to keep the code slow, otherwise people will stop wanting to upgrade their hardware. If this were not the case, why would .NET exist?

    you dumbass. the .net is the best and fastest thing ever invented in that category.

  • JS Programmer (unregistered)

    Does anyone else ever find themselves doing this for things like console.log in JavaScript? The infuriating disasters that follow ever being in a browser that doesn't declare the console object are such that I usually wrap them to make sure my code fails gracefully if/when a browser throws a hissy fit.

  • (cs) in reply to facilisis
    facilisis:
    Shagen:
    You have got to keep the code slow, otherwise people will stop wanting to upgrade their hardware. If this were not the case, why would .NET exist?

    you dumbass. the .net is the best and fastest thing ever invented in that category.

    ?

  • et (unregistered) in reply to facilisis

    I have seen so many crap sites in ASP.net, most of the time i find websites in ASP.net horribly slow (Especially when they are using webforms), sometimes because of the _VIEWSTATE string theres like a few hundred kilobytes, i suspect.

    Stuff rarely works as intended with webforms (Mostly because some ASP.net developers think that their framework is so great that they dont need to think for themselves), i have seen too many sites with webforms that breaks every rule of usability, like you hit enter in a searchfield and get an error about not providing the propper credentials for a login, because all the shit is thrown in one form - I know that you can do several forms with webforms, but it seems like most ASP.net developers dosn't.

    Im getting kind of tired of the PHP hate, yes its inconsistent in naming conventions, has a handfull of quirks (Like boolean comparison), but when you haven't used it since PHP3 then please do shut the fuck up, or at least provide a better AND fresh argument.

    "I used ASP.net 2.0 it was crap, asp.net is crap!"

    Not really a good way of making your point is it?

  • et (unregistered) in reply to et

    Just to support my argument regarding __VIEWSTATEs:

    php -r "echo strlen(file_get_contents('horrible-viewstate-from-visitdenmark-dot-com-search.txt'));" 294420

    294KB viewstate, u mad ?

Leave a comment on “The Phony”

Log In or post as a guest

Replying to comment #375353:

« Return to Article