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

A small problem in running PHP4 under PHP5 - $row[fieldname]

P: n/a
xhe
I have just upgraded my php version form php4 to php5. and I met this
problem, and don't know if you know the solution.
My site was written in PHP4, and most parts can be running smoothly in
PHP5, only that in old version, I can use $row[fieldname] to access
the data in database directly, no need to put double quote around
fieldname. BUT in PHP5, this is wrong, I got error message "undefined
constant". I know this is because PHP5 see the fieldname without
double quote as constant instead of name of field. I know the slowest
solution is to add double quotes one by one, but this will take a lot
time.
So are there any solution to change configuration in php.ini and let
PHP5 accept this kind of usage just like that in PHP4?
Thanks.

Jun 29 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jun 29, 1:04 pm, xhe <hexuf...@gmail.comwrote:
I have just upgraded my php version form php4 to php5. and I met this
problem, and don't know if you know the solution.
My site was written in PHP4, and most parts can be running smoothly in
PHP5, only that in old version, I can use $row[fieldname] to access
the data in database directly, no need to put double quote around
fieldname. BUT in PHP5, this is wrong, I got error message "undefined
constant". I know this is because PHP5 see the fieldname without
double quote as constant instead of name of field. I know the slowest
solution is to add double quotes one by one, but this will take a lot
time.
So are there any solution to change configuration in php.ini and let
PHP5 accept this kind of usage just like that in PHP4?
Thanks.
It didn't technically work in PHP4, either. You just didn't have
error reporting turned on so you never really noticed. While you
might see it as a hassle to add the quotes back in it is the correct
way to fix it. The way to "fix" it in PHP5 is to disable error
reporting -- although you haven't really fixed anything that way. I
strongly suggest you actually correct the code.

Jun 29 '07 #2

P: n/a

"xhe" <he******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
>I have just upgraded my php version form php4 to php5. and I met this
problem, and don't know if you know the solution.
My site was written in PHP4, and most parts can be running smoothly in
PHP5, only that in old version, I can use $row[fieldname] to access
the data in database directly, no need to put double quote around
fieldname. BUT in PHP5, this is wrong, I got error message "undefined
constant". I know this is because PHP5 see the fieldname without
double quote as constant instead of name of field. I know the slowest
solution is to add double quotes one by one, but this will take a lot
time.
So are there any solution to change configuration in php.ini and let
PHP5 accept this kind of usage just like that in PHP4?
Thanks.
Hi xhe,

I would not recommend changing the settings.
Why not fix the problem now? You will only run into it again later.

Find a regular expression that replaces the [ ] with [" "]
or do search and replace in a decent text editor.
Its not that hard to do.

Richard.
Jun 29 '07 #3

P: n/a
xhe schrieb:
I have just upgraded my php version form php4 to php5. and I met this
problem, and don't know if you know the solution.
My site was written in PHP4, and most parts can be running smoothly in
PHP5, only that in old version, I can use $row[fieldname] to access
the data in database directly, no need to put double quote around
fieldname. BUT in PHP5, this is wrong, I got error message "undefined
constant". I know this is because PHP5 see the fieldname without
double quote as constant instead of name of field. I know the slowest
solution is to add double quotes one by one, but this will take a lot
time.
No, the behaviour hasn't changed. PHP4 also treats the fielname without
quotes as a constant. Undefined constants that a script tries to access
are implicitly/conveniently defined to have their name as content so the
script works as expected. And it still works in PHP5. You just use an
installation with more strict error_reporting. Have a look at
configuring the error reporting settings or (better) change your script
to use strings like in $row['fieldname'].

OLLi
--
"No self-respecting man in Iowa goes anywhere without beer."
[LOST 122]
Jun 30 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.