![]() |
Why is $foo[bar] wrong?
I see this alot in hacks and the vb code in general, so I thought I'd quote the PHP manual:
Quote:
|
its a handy way of replacing vars with their value within strings.
its quicker to go: echo ("sometext $foo[bar] some more text"); than it is to go: echo ("sometext ".$foo['bar']." some more text"); ...but yes it is possible this might cause problems in the future with backwards compatibility - fair point. |
It's just lazy programming. vB3 has everything done properly, i.e.
$foo['bar']; $foo["$bar"]; |
There is nothing wrong with using $foo[$bar] since $bar can never be a constant, and it's an expression. And in case you use a value from an array as an index for another array, using $post[$user['userid']] is better than $post["$user[userid]"] (since you can't do $post["$user['userid']"]).
|
Firefly do you help programme vBulletin aswell?
|
Well if $bar happens to be -1 than $foo[$bar] blows up if you are expecting -1 to be a string. $foo["$bar"] doesn't blow up.
|
All times are GMT. The time now is 04:43 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|