Page 1 of 1

Variable confusion

Posted: Fri Nov 11, 2016 3:31 am
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.

Re: Variable confusion

Posted: Fri Nov 11, 2016 5:08 am
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.

Re: Variable confusion

Posted: Sat Nov 12, 2016 1:30 pm
by Seeeks
That explains it, although I will forever be wondering how on earth the code was working with mismatched case.

Re: Variable confusion

Posted: Sat Nov 12, 2016 4:47 pm
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.