Reputation: 12242
I'm trying to make the client's legacy PHP application to work for PHP 5.3. I see this kind of code a lot:
$SETTINGS[cart][picsize] = "100";
$settings[user][time] = 123;
1) Are variables case-insensitive in PHP? Is $SETTINGS
same as $settings
?
2) I'm getting 'undefined constant'
for the cart
, picsize
, etc. and they don't seem to be defined anywhere in the codebase. Did some older versions of PHP allow referencing array indices without quotes, or what is going on here?
Upvotes: 1
Views: 65
Reputation: 14649
Variables are case sensitive, functions and classes are not.
It could have been that your PHP configuration had a certain level of error reporting turned off and you never saw the error. It might have worked for you because those undefined constants will get turned into strings. (credit: @watcher). You should always reference associate array indexes with quotes, unless they are not a string. Strings should always be quoted, unless you have defined a constant. You do not have to quote integers, double or bool.
$SETTINGS["cart"]["picsize"] = 100;
$settings[user][time] = 123;
Those two statements are completely different and are in no way related as far as variables are concerned. Regardless if there only difference is upper case and lower case. They are still not the same.
Upvotes: 2