By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

Odd variable Bug

P: n/a
I am using PHP 4.3.4 and found something strange with a variable name.
When I try to use "$company" variable (lowercase), I get odd behavior
from that variable. The name of my php file is "company.php" but I
didn't think that php associated them together. The behavior is that
"$company" will take on values of the previously accessed $_GET
variable. I fixed it by using "$company_info" variable instead but I
would really like to know why the "$company" variable seems to be a
landmine.

The code includes the core Pear libraries and the pear IT library but
nothing else. I thought that system variables took the form of
"$_VAR"?

If anyone has run into odd behavior like this before let me know so I
can
find out what variables to avoid in the future.

Sam
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 30 Jul 2004 17:18:41 -0700, gl********@adelphia.net (Lost arcade)
wrote:
I am using PHP 4.3.4 and found something strange with a variable name.
When I try to use "$company" variable (lowercase), I get odd behavior
from that variable. The name of my php file is "company.php" but I
didn't think that php associated them together. The behavior is that
"$company" will take on values of the previously accessed $_GET
variable. I fixed it by using "$company_info" variable instead but I
would really like to know why the "$company" variable seems to be a
landmine.

The code includes the core Pear libraries and the pear IT library but
nothing else. I thought that system variables took the form of
"$_VAR"?

If anyone has run into odd behavior like this before let me know so I
can
find out what variables to avoid in the future.


Any $_GET("varname"> will override $varname, no?

--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #2

P: n/a
"Lost arcade" wrote:
I am using PHP 4.3.4 and found something strange with a variable name. When I try to use "$company" variable (lowercase), I get odd behavior from that variable. The name of my php file is "company.php" but I didnt think that php associated them together. The behavior is
that
"$company" will take on values of the previously accessed $_GET
variable. I fixed it by using "$company_info" variable instead but I would really like to know why the "$company" variable seems to be a landmine.

The code includes the core Pear libraries and the pear IT library but nothing else. I thought that system variables took the form of
"$_VAR"?

If anyone has run into odd behavior like this before let me know so I can
find out what variables to avoid in the future.

Sam


Sam, that behavior is due to register_globas being ON. This is not a
good thing. You would want register globals off. It "should" be
OFF by default in your version of php.
http://www.desilva.biz/apache/regblsoff.html

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Odd-vari...ict135185.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451438
Jul 17 '05 #3

P: n/a
On 30 Jul 2004 21:58:49 -0400, steve <Us************@dbForumz.com>
wrote:
"Lost arcade" wrote:
I am using PHP 4.3.4 and found something strange with a variable

name.
When I try to use "$company" variable (lowercase), I get odd

behavior
from that variable. The name of my php file is "company.php" but

I
didnt think that php associated them together. The behavior is
that
"$company" will take on values of the previously accessed $_GET
variable. I fixed it by using "$company_info" variable instead

but I
would really like to know why the "$company" variable seems to be

a
landmine.

The code includes the core Pear libraries and the pear IT library

but
nothing else. I thought that system variables took the form of
"$_VAR"?

If anyone has run into odd behavior like this before let me know so

I
can
find out what variables to avoid in the future.

Sam


Sam, that behavior is due to register_globas being ON. This is not a
good thing. You would want register globals off. It "should" be
OFF by default in your version of php.
http://www.desilva.biz/apache/regblsoff.html


Heh. WAAAAY back in a previous version somewhere, it must have been on
by default? I've not used the same variable name as a $_GET or $_POST
variable because I thought I had to. Not that it hurts to use
slightly different names.

(I usually use:

$VariableName = $_POST['variable_name'];

)


--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #4

P: n/a
"Gary L. Burnore" wrote:
On 30 Jul 2004 21:58:49 -0400, steve
<Us************@dbForumz.com>
wrote:
"Lost arcade" wrote:
I am using PHP 4.3.4 and found something strange with a variable
name.
When I try to use "$company" variable (lowercase), I get oddbehavior
from that variable. The name of my php file is "company.php" but
I
didnt think that php associated them together. The

behavior is that
"$company" will take on values of the previously accessed $_GET variable. I fixed it by using "$company_info" variable instead
but I
would really like to know why the "$company" variable seems

to be
a
landmine.

The code includes the core Pear libraries and the pear IT

library
but
nothing else. I thought that system variables took the form

of "$_VAR"?

If anyone has run into odd behavior like this before let me

know so
I
can
find out what variables to avoid in the future.

Sam


Sam, that behavior is due to register_globas being ON. This is

not a
good thing. You would want register globals off. It "should"

beOFF by default in your version of php.
http://www.desilva.biz/apache/regblsoff.html


Heh. WAAAAY back in a previous version somewhere, it must have been

on by default? Ive not used the same variable name as a $_GET or
$_POST
variable because I thought I had to. Not that it hurts to use
slightly different names.

(I usually use:

$VariableName = $_POST[variable_name];

)


register_globas is a left-over from older versions of php. When you
posted a variable, it would be available both as $_POST[xyz] and
$xyz. That was a BAD thing, since someone could insert some POST or
GET variables and they would show up as regular variables.

So as you state, one should always use $_POST or $_GET to access such
variables, and if at all possible (except due to old code) turn off
register_globals.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Odd-vari...ict135185.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451493
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.