Private global
-
<?php class Email { private $text = false; public function __construct() { global $text; $this->text = $text; ... } ... } ?>
-
The private member "this->text" is assigned the content of the global variable also named "text". Stupid? Yes. Valid? Yes.
-
Admittedly, my PHP is beyond rusty, but this seems like a pretty minor WTF at best. Can a competent PHP programmer explain why this is such a huge WTF? Or, failing that, can your average PHP programmer explain why this is excellent code, thus allowing me to invert your logic to explain why it's actually a WTF?
-
Yeah, pretty minor WTF, in the way that any global variable is a minor WTF.
I can understand why the object might need to record for its own use the current state of an external variable; I'm unconvinced that it couldn't be done better by passing it via the constructor.
-
Get this guy a mug.
-
I like the idea. Let's make a private field so nobody messes with it. And then let's rely on a global variable.
So instead of having
$email = new Email($text);
which actually shows what information is used, the user of this great class will have to write
$email = new Email();
and hope to remember to set the $text variable. In fact, it can't be any variable. It has to be $text.
Oh and by the way, if he uses $text to store something else on the way, he's screwed.
Great misuse of object-oriented programming.
-
@bstorer said:
Or, failing that, can your average PHP programmer explain why this is excellent code, thus allowing me to invert your logic to explain why it's actually a WTF?
You rang?
Basically, the problem here is that the variable isn't assigned by reference. That means somebody can come along later and change your global $text variable, and you wouldn't even know. Meanwhile, there's no easy interface for you to change the private variable because it's all hidden inside and shit. If it were a reference, you could just change the global variable anywhere without needing to worry if you have a reference to the object. And it's changed everywhere, in all instances of this class, at the same time. Now that's the kind of power you only get with a language like PHP.
-
Another minor WTF in the choice of the name here...
"An Email class with a $text member ? OK. Must be some str... a ... boolean ? Doesn't it make us assume it will be some.... *text* ?"
-
The monostate pattern: http://www.objectmentor.com/resources/articles/SingletonAndMonostate.pdf
That said, I think more context is needed: how is the class & its members used?
-
-
-
Warble Gloaming.
-
-
Pribal Glovate.
-
@too_many_usernames said:
@PJH said:
I think you'll find they both are.Warble Gloaming.
Wait a minute...at least one of those is an actual English word!
Happily, the spoonerised version makes as much sense as the un-spoonerised version. Figuring out which is which is left as an exercise for the reader.
-
-
@PJH said:
I think you'll find they both are.
I suspected as much, which is why I used the CYA verbiage "at least one..."Yes, I am actually so lazy as to not go check a dictionary.
-
V.T. labial grope.
-
@dhromed said:
That means you're either on drugs or so pretentious that you deserve to be beaten to death with your own self-importance.@PJH said:
Warble Gloaming.
I like tha Radiohead song.
-
@bstorer said:
That means you're either on drugs or so pretentious that you deserve to be beaten to death with your own self-importance.
No, I just like Radiohead a lot.
I thought the ticket price for Westerpark a few years ago was a bit steep, but eh: what price an excellent time?
-
@dhromed said:
what price an excellent time?
$7. At least that's what morb's mom charges.
-
-
@dhromed said:
She has a tricky pricing model: the sex is free, but you have to pay her to leave. And when the wave of shame and revulsion hits you immediately after coitus, you too would pay a damn sight more than $7 to be rid of her.@bstorer said:
$7. At least that's what morb's mom charges.
You paid for that?
-
@morbiuswilters said:
Basically, the problem here is that the variable isn't assigned by reference.
Unless that variable was an object. Then it would be assigned by reference unless you used the clone operator (Well, in 5.2+ at least)... Yet another WTF about the language that can come in real handy if you're expecting it, or burn you hard if you're not...
-
@bstorer said:
And when the wave of shame and revulsion hits you immediately after coitus, you too would pay a damn sight more than $7 to be rid of her.
NOOOOOOO NO CUDDLING NOOO----- (muffled noises then emanate from betwixt undulating belly flaps)
-
For those who asked for more context... $text[type][page][key][sub_key][sub_sub_key] is a five-dimensional-array containing _all_ texts and actually the code looks like this:
class Email { private $language = false; private $text = false; ... public function __construct($type,$case,$receiver,$data) { global $text; ... $this->language = $text; $this->text = $this->language['global']; } public function sendEmail($subject = false, $message = false) { ... switch($this->type) { case 'direct': $subject = $this->language['emails']['e_'.$this->case]['subject']; $body = $this->language['emails']['e_'.$this->case]['body']; $smarty->assign('text',$this->text); ... break; ... } } ... }
-
@ircmaxell said:
Unless that variable was an object. Then it would be assigned by reference unless you used the clone operator (Well, in 5.2+ at least)... Yet another WTF about the language that can come in real handy if you're expecting it, or burn you hard if you're not...
Objects have always been automatically by-reference in PHP5. It is far, far superior to having to explicitly pass all objects by-reference.
-
@sui said:
For those who asked for more context... $text[type][page][key][sub_key][sub_sub_key] is a five-dimensional-array containing all texts and actually the code looks like this:
Sweet fancy moses! From the OP one couldn't possibly have guessed what a mess this is! I think they just started using smarty and found the little arrow cool, so they checked the PHP manual how to create more occasions for using the arrow.
-
@sui said:
For those who asked for more context... $text[type][page][key][sub_key][sub_sub_key] is a five-dimensional-array containing _all_ texts and actually the code looks like this:
It's Alderaan all over again
-
@Brian Fernandes said:
Alderaan?@sui said:
For those who asked for more context... $text[type][page][key][sub_key][sub_sub_key] is a five-dimensional-array containing _all_ texts and actually the code looks like this:
It's Alderaan all over again
Were you perhaps thinking of some other extrasolar object related to computer languages, like ALGOL, or do you just mean that it should be destroyed by a massive laser from a distance of six planetary orbits or so?
-
@sui said:
For those who asked for more context... $text[type][page][key][sub_key][sub_sub_key] is a five-dimensional-array containing _all_ texts and actually the code looks like this : ...
Clearly there's a flaw here : they haven't foresighted the hypothetical use of a sub_sub_sub_key... what a shame.
-
-
@dhromed said:
I like tha Radiohead song.
That's because you're so fucking special
-
@belgariontheking said:
Doesn't that make you the creep?@dhromed said:
I like tha Radiohead song.
That's because you're so fucking special
-
@bstorer said:
@belgariontheking said:
I'm a winner. What the hell am I doing here?@dhromed said:
Doesn't that make you the creep?I like tha Radiohead song.
That's because you're so fucking special
-
@dhromed said:
I was browsing some pretty fucking sad wikis the other day, after reading an early episode of Irregular Webcomic, and it mentioned the distance here.@DaveK said:
six planetary orbits
How do you figure?
OTOH, on the bright side, I did find out that five minutes after the second Death Star exploded, the entire surface of the moon of Endor was buried to a depth of dozens of meters in metallic radioactive wreckage, thus genociding all those fucking stupid little teddy bears right into extinction, which brought me joy beyond words :-D
-
@DaveK said:
genociding all those fucking stupid little teddy bears right into extinction, which brought me joy beyond words :-D
That is such great news!
-
@dhromed said:
@DaveK said:
genociding all those fucking stupid little teddy bears right into extinction, which brought me joy beyond words :-D
That is such great news!
Ewok Steak
-
@Lorne Kates said:
@dhromed said:
@DaveK said:
genociding all those fucking stupid little teddy bears right into extinction, which brought me joy beyond words :-D
That is such great news!
Ewok Steak
Tastes like yub nub.
-
@Lorne Kates said:
Ewok Steak
You know like when you barbecue things and you take the meat and package it in foil to seal in the moisture and let it sit on the heat for about 15-20 minutes, so that you get that succulent, delicious meat?
Yeah.
So this would be like Forest Moon Barbecue, right?
-
-
Lal.
I would totally appreciate that image more if I got the reference.
-
You've.. never seen.. Good Eats?
(Insert wtf face here)
Imagine if someone grew up watching Mr. Wizard, McGuiver and Monty Python, then decided to become a chef. That's Alton Brown, the guy in the picutre.
Even if you don't want cooking shows, you've got to see at least one episode. Given your tags, try [url=http://www.youtube.com/watch?v=tXNJyhqb5qg&feature=PlayList&p=6FDA8D529A441A81&index=16]this one: season 7 "Raising The Steaks"[/url]
-
@Lorne Kates said:
You've.. never seen.. Good Eats?
(Insert wtf face here)
He's European. If it doesn't involve ABBA, being raised as a pansy who believes he is superior to Americans because he doesn't know how to operate a gun, surrendering to Nazis or being a drunk, degenerate, God-hating socialist who hates God, he doesn't want to hear it.
@Lorne Kates said:
Even if you don't want cooking shows, you've got to see at least one episode. Given your tags, try this one: season 7 "Raising The Steaks"
The "meat" he is referring to is of the human male variety, but he's no cannibal.
-
@morbiuswilters said:
The "meat" he is referring to is of the human male variety
Uh, no it's not.
That's just what you make of it every time, you big fag.
Because you apparently have a massive craving for male genitals -- apparently mine in particular, but HEY I don't swing that way, my dear.
-
I'm American, and I didn't get it either. Of course, I don't watch TV.
-
-
@blakeyrat said:
I'm American, and I didn't get it either. Of course, I don't watch TV.
Go back to Dutchland
-
@Lorne Kates said:
Go back to Dutchland
No no, we don't want him and his sullen ways here.
-
@blakeyrat said:
I'm American, and I didn't get it either. Of course, I don't watch TV.
Actually, I didn't get it either. I don't have any kind of TV service and only have a couple of shows I like enough to download from torrents. I did recognize the Food Network logo, though, and the guy does look kind of familiar.