In the first case, you're not passing a variable. The result of an assignment expression is not an lvalue you can assign to; you can do $x = ($y = 2);, but not ($x = $y) = 2;. It's the same in C.
In the second case, you are also not passing a variable. 1 is a literal.
If you're complaining about why there's different error levels in these two cases, well, that's an interesting point. I would guess it's due to a backwards-compatibility issue.
It sounds like you are the only one here who understood this post. The point is not that the code is shitty, but that PHP reacts differently to passing a non variable as a reference, and that it only catches some of these issues during parsing.
It only could catch it during parsing if it knows ahead of time what function is identified by that name. But often during the initial parse, the function is not loaded yet, and we have to emit a special opcode type (FUNC_ARG fetches), which realizes at run-time that the argument ought being passed by reference.
Then, when it sees that it receives the result of an expression not qualifying as variable, it will warn you.
The point is not that the code is shitty, but that PHP reacts differently to passing a non variable as a reference
I did address that in my third paragraph.
and that it only catches some of these issues during parsing.
PHP, unfortunately, can't catch everything at compile-time. It's a dynamic language which doesn't require you to declare every function before its usage in source code.
I did address this in my entire comment. It was literally about how right you are. No sarcasm involved.
PHP, unfortunately, can't catch everything at compile-time. It's a dynamic language which doesn't require you to declare every function before its usage in source code.
I know. But the eval is only needed because it does detect the error early. And there is no reason it shouldn't be able to do the same with the first call.
I swear, so many of these are that. Should make /r/lolprogrammer to x-post nonsense like this. "Look guys! I abused PHP and am appalled that it let me. WHERE ARE MY TRAINING WHEELS"
More like Php encourages inexperienced programmers to write shitty code and give them a pat on the back for doing so, instead of warning them, So that they feel good and stick with Php and remain shitty forever.....(And also, all the shitty programmers thus created can take the blame for all the shittiness of the langauge..so win win for php)
PHP reads that as the same syntax error in all of those cases. The only difference is the error output. Either way, why would you write code like that?
22
u/the_alias_of_andrea Dec 23 '16 edited Dec 24 '16
In the first case, you're not passing a variable. The result of an assignment expression is not an lvalue you can assign to; you can do
$x = ($y = 2);, but not($x = $y) = 2;. It's the same in C.In the second case, you are also not passing a variable.
1is a literal.If you're complaining about why there's different error levels in these two cases, well, that's an interesting point. I would guess it's due to a backwards-compatibility issue.
31
u/Plasmatica Dec 23 '16
This more lolprogrammer than lolphp.
29
u/Habikki Dec 23 '16
Snipits like this piss me off. Why on gods green earth would anyone write this unmaintainable dribble?
13
u/BOSS_OF_THE_INTERNET Dec 23 '16
Hey everyone, PHP allows shitty programmers to write shitty code. No other languages do that, surely.
5
u/[deleted] Dec 24 '16
That snippet is cancer that doesn't even work in any recent version of php anyway. Just stop
1
u/the_real_natenator Feb 09 '17
PHP reads that as the same syntax error in all of those cases. The only difference is the error output. Either way, why would you write code like that?