0

I tried searching for an answer, but I'm not sure how to word the question so that it fits into a search box.

I found out a month or so ago that if you are accessing variable data like $_POST or after a mysql_fetch you can use $row but it also seems to work just fine when you don't use the quotes, i.e. $_POST[user] and $row[id].

So I've built two entire websites without using the quotes, but recently I had to do some work on one of the sites and when I turned on error checking every instance where I didn't use the quotes generated a notice. I've also noted that this site is "really" slow and that got me to wondering. . . (see? how do you fit that into a textbox?)

Does anyone know if not using the quotes around the field names slows PHP down? Are there any other problems created by not using the quotes?

Ardav, I'm looking at you here. :)

David

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by dietdew12z
0

http://stackoverflow.com/questions/5444207/using-arrays-without-putting-the-key-in-quotes

It is correct PHP to use quotes, although it works without. This can lead to errors, should you have a const defined with that name for example.

$row = array ('user' => 'foo', 'myusername' => 'bar');
define('user', 'myusername');
echo $row[user];
echo $row['user'];

So, my guess it it will be slower without. I think it will try to find a matching const first, and if there isn't any revert to the string version.

Edited by pritaeas: n/a

0

Okay. I think I won't worry about going back and fixing the other site. Thanks, Pritaeas! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.