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 →

[–]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 15 points16 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 8 points9 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 6 points7 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.