Variable confusion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Seeeks
Forum Newbie
Posts: 17
Joined: Sat Oct 22, 2016 10:42 am

Variable confusion

Post by Seeeks »

Is it possible that variables are not always case sensitive? When I moved my website from the local environment to the web server, a lot of things stopped working and had to be fixed. Among one of the things was that I had assigned variables $userid and $charid and then tried to address them as $userId and $charId, with the Id starting with a capital letter. Yet it appears that that somehow worked locally, because it certainly didn't fail like it did online.

Also, in a lot of places I was referring a variable as $userid which wasn't defined anywhere on the page, (the actual name of the variable was $currentUser) yet somehow it never failed to work. The value of the variable was placed in a hidden field in a form, and if the next page didn't have the GET variable then it should fail. Yet somehow it was working. It totally blows my mind. It must've been getting the $userid definition from somewhere but I can't see how or where. Um, is it possible that something in some versions of php automatically converts GET information into variables with the same name? That's the only explanation I could think of. Maybe this is far fetched but I am totally baffled about how it's even vaguely possible the code was working in the first place with all the bugs.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Variable confusion

Post by requinix »

Seeeks wrote:Is it possible that variables are not always case sensitive?
Variables are always case-sensitive.
Seeeks wrote:is it possible that something in some versions of php automatically converts GET information into variables with the same name?
The feature was called register_globals and was removed in PHP 5.4. It worked just as you said.
Seeeks
Forum Newbie
Posts: 17
Joined: Sat Oct 22, 2016 10:42 am

Re: Variable confusion

Post by Seeeks »

That explains it, although I will forever be wondering how on earth the code was working with mismatched case.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Variable confusion

Post by Christopher »

Seeeks wrote:That explains it, although I will forever be wondering how on earth the code was working with mismatched case.
My guess is that register_globals was on. However, it might have been issuing a warning that the variable was not defined, but the code still worked with those vars undefined. An upgrade may have changed a warning to an error.
(#10850)
Post Reply