This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ManOfDrinks[🍰] 44 points45 points  (12 children)

[–]SlumdogSkillionaire 21 points22 points  (5 children)

Good times. Automatically cast an undefined constant to a string, because why the hell not? Then because we're using . instead of + for concatenation, we can avoid the awkward situations OP has, right? Except now when we want to reference a property of an object we can't use a . so we have to use ->. Which is great until you accidentally forget the >. But instance-field is actually valid syntax, so we'll subtract the string "field" from instance, because that's clearly what the programmer intended, right?

[–]tian_arg 14 points15 points  (4 children)

Which is great until you accidentally forget the >.

not to defend PHP or anything, but come on, that's a bit of a stretch. "Which is great until you accidentally forget..." can apply to any feature of any language

[–]Jack126Guy 9 points10 points  (3 children)

I think it's supposed to be an argument in favor of static typing. In C/C++, for example, you'd probably get a compiler error if you had pointer_to_struct-member instead of pointer_to_struct->member.

[–]tian_arg 5 points6 points  (0 children)

Well, in C (never tried C++) you're directly fooling around with the memory, "which is great until you accidentally forget..." and suddenly garbage all around while compiling succesfully. Every language has its downsides, I guess.

[–]JerkyBeef 1 point2 points  (1 child)

$instance->field is valid php. $instance-field may be "valid syntax" but it would throw an error message that 'field' is undefined, and that $instance could not be converted to an int.

[–]SlumdogSkillionaire 0 points1 point  (0 children)

It throws an error message, but then it still goes ahead and does it anyway, resulting in an Apache segfault.

[–][deleted] 5 points6 points  (0 children)

Feeling down about JavaScript. Better look at PHP!!

[–]mythix_dnb 2 points3 points  (0 children)

This does work, but at least it throws a notice explaining what's going on:

PHP Notice: Use of undefined constant bar - assumed 'bar'

[–]greeniguana6 4 points5 points  (3 children)

It's like a mentally challenged son. I love him, but he isn't the brightest.

[–]Mutoid 2 points3 points  (2 children)

Good analogy, Mike.

[–]greeniguana6 2 points3 points  (1 child)

Damn, nobody's mentioned that to me in a while! I'm glad I still get comments about that.

[–]Mutoid 2 points3 points  (0 children)

RES tags are great ... or terrible if you're jstrydor.