• Anon (unregistered)

    This is horrible, but the unserialise(serialise()); can have some use if you need an exact copy of a class and all its references.

    For example:

    class A{

    var $b;

    function __construct(){

    $this->b = new B; }

    function setB($input){

    $this->b->b_var = $input; }

    }

    class B{

    var $b_var = 'old Val'; }

    $A = new A;

    $C = clone $a;

    $A->setB('new var');

    echo $A->b->b_var; echo $C->b->b_var; //Both will be new var as B is referenced

    Serialising will clone all the referenced objects too to get around this god awful shit storm

  • nobis (unregistered) in reply to Kuli
    Kuli:
    void*:
    In C, C++, C#, Java, etc. (even SQL) you can just use a cast to change the type. Much simpler.

    Wow! Well, ...

    no.

    This might work with some forms of C "objects", but with C++ virtual methods it might get messy (depending on implementation details). And in Java you can't just cast between arbitrary types.

    It might help to actually think before posting.

  • (cs) in reply to nobis
    nobis:
    Kuli:
    void*:
    In C, C++, C#, Java, etc. (even SQL) you can just use a cast to change the type. Much simpler.

    Wow! Well, ...

    no.

    This might work with some forms of C "objects", but with C++ virtual methods it might get messy (depending on implementation details). And in Java you can't just cast between arbitrary types.

    It might help to actually think before posting.

    In C++, if the types aren't very closely related, you're pretty much guaranteed to incinerate millions of people in a nuclear fireball, that being the usual consequence of running code with undefined behaviour on a DeathStation 9000. In fact, even if the types are closely related, the behaviour is still undefined, so just don't do it.

  • persto (unregistered) in reply to Shoreline

    Well okay, I'll take a shot at this.

    First there are the classics. SmallTalk is something of a gold standard of well-designed languages. Although there are certain dialects of assembly language which which are a disaster (e.g. x86) the assembly language for the SPARC processor line is usually held up as an example of a good assembly language. It was actually used for teaching assembly back when I was in school despite the relatively limited popularity of the processors themselves.

    As for more recent languages, Lua is often mentioned as an example of a well-designed language and fairly popular in at least one domain (embedded scripting) so surely it is a good language.

    Let me go out on a limb a bit and suggest Python as another good language. Some people don't like the rules about whitespace but even those people say it's more of a matter of taste. Aside from that I don't hear a lot of complaints about it. I use it myself without constantly running into dumbness (as for example happens all the time when I write PHP). It seems to be a good language.

    I have also heard Haskell described as the best functional language, though I admit that I know very little about it.

  • Your Name (unregistered) in reply to Y_F

    Presumably he was looking for the profile in order to find and beat this person.

  • C-Derb (unregistered)
    $canBeDone !== $shouldBeDone;
  • (cs) in reply to MustBeUsersFault
    MustBeUsersFault:
    it's not a wtf in itself, much more the symptom of a deeper, much worst wtf somewhere in the code base and a demented coder in the office.
    So, a brilliant solution to the symptom, not the problem?
  • nom (unregistered) in reply to 50% Opacity
    50% Opacity:
    nom:
    Sure, why not? English has a very complicated grammar

    I'd disagree. English grammar is one of the simpler ones. It may have a couple of rough edge cases, but mostly English grammar is dead simple.

    By natural language standards it's about average, in that essentially all natural languages have an undecidable grammar, making them effectively impossible to parse in the general case, whereas the only programming language (that anyone takes seriously) with an undecidable grammar is C++.

    So perhaps I'm spoiled by writing parsers.

    50% Opacity:
    nom:
    and no consistent set of pronunciation rules.

    The pronunciation of words varies from place to place, but this is the case with any language that is spoken among geographically divers people which do not all communicate each and every day with each other. English suffers from this a lot since it's probably the most geographically diverse language to date. Since there's only one, no, sorry, two spelling systems, you're bound to come across inconsistencies.

    Spanish is about as geographically diverse, but within each dialect, there's an unambiguous way to pronounce each valid spelling of a word. Or, as Davos says, "why is there a 'G' in 'night'"?

    50% Opacity:
    nom:
    It's basically a hodgepodge of features stolen from other languages, hastily grafted together with little thought to consistency, that is widely used due to familiarity and network effects.

    Name one natural language that does not fit this definition.

    That's the joke. And that's why PHP, despite being terrible, will continue to be used for the majority of web apps for the forseeable future, whereas your nice clean Haskell or whatever will wallow in obscurity next to Esperanto.

    50% Opacity:
    Japanese and German

    Oh well there's your problem. The Romance languages are generally better maintained.

  • (cs) in reply to Shoreline
    Shoreline:
    Dogsworth:
    PHP. TRWTF.

    I hear a lot how this or that language is bad. Could somebody give me a list of languages which are good?

    That depends entirely on who is answering the question. In my case, just about any language where you don't have to do memory management yourself is good.

  • trtrwtf (unregistered) in reply to Sitethief
    Sitethief:
    Why do people blame bad programming in a language, for example PHP, on the language itsself?

    Does language design matter? I think it does, and I think the point of language design is to produce a language which encourages good usage and makes it easier to write well than to write poorly.

    PHP fails to do this, by any standard. The design of the language makes it very difficult to write good code, and in fact encourages lousy code. This is well documented*, and not even worth arguing about.

    *For example, you can start here: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

    or here: http://www.php.net/manual/en/

  • rez (unregistered) in reply to 50% Opacity

    I wouldn't know about grammar but inconsistencies in pronunciation are abundant even in one spelling system on one geographical location. Just try to read this beautiful poem aloud in whatever local english dialect you like: http://pauillac.inria.fr/~xleroy/stuff/english-pronunciation.html

  • (cs) in reply to Sir Bedevere
    Sir Bedevere:
    Geoff:
    This code would be perfectly happy to try and turn a duck into a car. It would be nice if it had duck-type style checks or something in it that would produce a useful error if you try and transmogrify something that won't work.

    For instance, it only works if duck.weight == car.weight, and CanBuildBridge(duck) returns true.

    It's a fair cop.

  • Munk (unregistered)

    Speaking as a PHP developer I saw this and my immediate reaction was 'Well sure, if you hate yourself you could do this'... sadly my second reaction was 'Did they really have to use serialize to do this' php objects are just glorified arrays so I'm pretty certain the same could be accomplished with a bit of casting, possibly through StdClass. Heck dude, if you want to shoot your foot off at least use the right gun.

  • (cs) in reply to FragFrog
    FragFrog:
    I really wonder what happens when you try this with incompatible classes. Presumably the deserializer will block such operations, but then again, it is generally best not to presume too much with PHP.

    I think you'll get: "Class....dismissed!"

  • (cs) in reply to Sitethief
    Sitethief:
    Why do people blame bad programming in a language, for example PHP, on the language itsself? Do we also blame bad grammar use on English?

    English sort of came into being. A programming language, theoretically, was designed by someone who had a purpose in mind. So, bad analogy. Use a car analogy next time.

  • Leo (unregistered) in reply to cellocgw
    cellocgw:
    Sitethief:
    Why do people blame bad programming in a language, for example PHP, on the language itsself? Do we also blame bad grammar use on English?

    English sort of came into being. A programming language, theoretically, was designed by someone who had a purpose in mind. So, bad analogy. Use a car analogy next time.

    Do we blame bad drivers on BMW?

  • Christopher Allen-Poole (unregistered)

    This is nothing new. The fact that people have been doing this has been making me nauseous for years.

  • trtrwtf (unregistered) in reply to Leo
    Leo:
    Do we blame bad drivers on BMW?

    No, we blame them on cell phones and texting and wankery of that sort.

  • Christopher Allen-Poole (unregistered) in reply to cellocgw
    English sort of came into being. A programming language, theoretically, was designed by someone who had a purpose in mind. So, bad analogy. Use a car analogy next time.

    PHP just sort of came into being though. It is a large combination of "Hey! Look at what I can do! Isn't that neat?"

  • (cs) in reply to Shoreline
    Shoreline:
    Dogsworth:
    PHP. TRWTF.

    I hear a lot how this or that language is bad. Could somebody give me a list of languages which are good?

    Haskell. It's the Dvorak of programming languages.

  • (cs) in reply to Geoff
    Geoff:
    Good luck to whoever gets to maintain this codebase.

    It'd be pretty easy. You just remove this function and replace all of its reference with the proper implementation.

  • Leo (unregistered) in reply to nom
    nom:
    Or, as Davos says, "why is there a 'G' in 'night'"?

    Depending on what you mean by "why", the answer is either "French printing presses" or "resistance to spelling reforms and no centralized spelling authority".

  • nom (unregistered) in reply to Leo
    Leo:
    nom:
    Or, as Davos says, "why is there a 'G' in 'night'"?

    Depending on what you mean by "why", the answer is either "French printing presses" or "resistance to spelling reforms and no centralized spelling authority".

    Shireen: "There just is."

  • trtrwtf (unregistered) in reply to chubertdev
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

  • Jarry (unregistered)

    i've found this in a codebase:

    public function loader($object) 
    {
       foreach ($object as $name => $value)	// ugly
       {
    	$this->$name = $value;
       };
    }
    
  • (cs) in reply to nom
    nom:
    Or, as Davos says, "why is there a 'G' in 'night'"?

    That's Sir Davos to you!

  • (cs) in reply to Leo
    Leo:
    cellocgw:
    Sitethief:
    Why do people blame bad programming in a language, for example PHP, on the language itsself? Do we also blame bad grammar use on English?

    English sort of came into being. A programming language, theoretically, was designed by someone who had a purpose in mind. So, bad analogy. Use a car analogy next time.

    Do we blame bad drivers on BMW?

    Nope, Audi. :)

  • (cs) in reply to trtrwtf
    trtrwtf:
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

    I just hope no one fails to see the point.

  • (cs) in reply to chubertdev
    chubertdev:
    nom:
    Or, as Davos says, "why is there a 'G' in 'night'"?

    That's Sir Davos to you!

    That's Ser Davos, you nonbeliever who will burn in the red flame!

  • trtrwtf (unregistered) in reply to chubertdev
    chubertdev:
    trtrwtf:
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

    I just hope no one fails to see the point.

    If they miss it, they're probably True Believers...

  • Joe (unregistered) in reply to nom
    nom:
    Or, as Davos says, "why is there a 'G' in 'night'"?
    lol itz bcuz u havent upd8d ur spelchkr to spel "nite" rite.

    (Wow, it was really hard to type that badly)

  • (cs)

    Pfft... reinterpret_cast has been doing this for ages.

  • lolatu (unregistered)

    The worst part about this code is the use of the '&' which treats the object passed in as a reference and changes it invisibly to outside code. I have never seen an actual use case where this would be preferable to the more maintainable non-referential usage like $object = changeClass($object, $newClass);

    Not that the rest is any better...

  • Brain damage (unregistered)

    Whoah, stop the flashbacks! This was much easier to do in FORTRAN back in the day, just screw up a COMMON declaration. Set f = 1.0 in one place, read i = 17448304640 somewhere else. Or use a bad FORMAT declaration to read integer, float, or character data into a variable of a different data type. No CAST required, just a momentary confusion (probably caused by experiencing the 60s).

  • (cs) in reply to trtrwtf
    trtrwtf:
    chubertdev:
    trtrwtf:
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

    I just hope no one fails to see the point.

    If they miss it, they're probably True Believers...

    I'm trying to think of Laser Disc, Betamax, and HD-DVD jokes that I can work in...

  • trtrwtf (unregistered) in reply to chubertdev
    chubertdev:
    trtrwtf:
    chubertdev:
    trtrwtf:
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

    I just hope no one fails to see the point.

    If they miss it, they're probably True Believers...

    I'm trying to think of Laser Disc, Betamax, and HD-DVD jokes that I can work in...

    Whoa, dude, step back. Betamax was totally better than VHS.

  • Axio (unregistered) in reply to 50% Opacity

    Have you ever read the chaos? http://www.mipmip.org/tidbits/pronunciation.shtml English pronunciation is very inconsistent!

  • TortoiseWrath (unregistered) in reply to trtrwtf
    trtrwtf:
    chubertdev:
    trtrwtf:
    chubertdev:
    trtrwtf:
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

    I just hope no one fails to see the point.

    If they miss it, they're probably True Believers...

    I'm trying to think of Laser Disc, Betamax, and HD-DVD jokes that I can work in...

    Whoa, dude, step back. Betamax was totally better than VHS.

    Indeed. And HD DVD was better than Blu-ray. Just saying.

  • EmperorOfCanada (unregistered)

    I have been reading the DailyWTF for years now and have seen the plethora of bad code such as 1000 "If" statements instead of a while loop. And stupid things such as using code calling a Database to do stuff that should have just been done in the code. But this code takes the WTF cake. I don't see its application but I can imagine that it is part of a much larger architectural WTF.

    The only possible excuse is that it is compensating for a WTF from another library and that in fact this is a brilliant workaround.

  • iusto (unregistered) in reply to 50% Opacity
    50% Opacity:
    nom:
    and no consistent set of pronunciation rules.
    The pronunciation of words varies from place to place, but this is the case with any language that is spoken among geographically divers people which do not all communicate each and every day with each other. English suffers from this a lot since it's probably the most geographically diverse language to date. Since there's only one, no, sorry, two spelling systems, you're bound to come across inconsistencies.

    I think you missed the point that he was trying to make (you nailed the first one).

    There are languages that have very easy and consistent pronunciation rules. And, by "pronunciation rules", he and I do not refer to the accent that various geographical places have. With very few and rule-based exceptions, languages such as Italian, Spanish, and pretty much every Slavic-based language (probably some others to) - are easy to understandably read by anyone who can grasp their very basic rule: each letter has one and only one sound.

    English, however, is a mess when it comes to this. Just when you manage to find 2 examples to build a rule for yourself, you encounter a word spelled in the same pattern with totally whacked pronunciation compared to the first 2.

  • (cs)
  • Someone (unregistered) in reply to Sitethief
    Sitethief:
    Why do people blame bad programming in a language, for example PHP, on the language itsself? Do we also blame bad grammar use on English?
    For the same reason we blame the Therac-25 instead of its operators.

    And people do blame English, at least to some extent. The truth of the matter is that there's plenty of blame to go around. People who program badly in PHP deserve some of it -- but at the same time, it is possible to make a bad tool.

    nom:
    the only programming language (that anyone takes seriously) with an undecidable grammar is C++.
    Depends on what you mean by "take seriously." Perl is even worse than C++ in some important ways.

    And while I wouldn't say I take Perl seriously, it is fairly widely-used. (Fortunately it seems to be that it's being supplanted by Python.)

  • (cs)

    Let's rename PHP to RGWI: Rube Goldberg Web Interpreter.

  • Calvin (unregistered)

    I believe the proper term for this type of operation is Transmogrify

  • (cs) in reply to Le Poete
    Le Poete:
    Geoff:
    ...This code would be perfectly happy to try and turn a duck into a car.

    Maybe that's the trick to get a floating car:-)

    Flying cars! Hurray!

  • trtrwtf (unregistered) in reply to Someone
    Someone:
    And while I wouldn't say I take Perl seriously, it is fairly widely-used.

    Best take that seriously, bro. JAPHs are just perl's way of saying "don't fuck with me. I can do this shit with one hand, and I might still be over here writing a haiku in your inittab"

    I take perl seriously. When I see that .pl extension, I don't know what's going to happen, but I know it's not going to be good.

  • Anon (unregistered)

    Ugly Duckling Typing

  • (cs)

    $last = new Last() ;

    $magicFSMClass->changeClass($last, "Frist");

  • Spencer (unregistered)

    I ran into a meta-WTF when trying to read the RSS feed on feedly. It decided to render all the html formatting in the code block. Of course this is valid PHP code, so it wasn't immediately clear to me that the WTF wasn't embedding tons of redundant span elements in their comments.

    /**
      * This will change the class
    type of the incoming object to be of
      * the type of newClassName
    that is passed in. You must make sure
      * that the classes of the
    object that you are changing to and from
    ...
  • Confused (unregistered) in reply to chubertdev
    chubertdev:
    trtrwtf:
    chubertdev:
    Haskell. It's the Dvorak of programming languages.

    Good analogy, dude!

    I just hope no one fails to see the point.

    Since I don't know much about Haskell, nor use Dvorak, what is the point?

Leave a comment on “Pot o' Gold”

Log In or post as a guest

Replying to comment #:

« Return to Article