NYCPHP Meetup

NYPHP.org

[nycphp-talk] Syntax question (was handling forms (relative newbie))

David Mintz dmintz at panix.com
Mon Oct 6 16:06:07 EDT 2003


On Mon, 6 Oct 2003, Aaron Fischer wrote:

> Quick question:  I noticed on some posts to my original question the
> syntax for accessing an array element of $_POST or $_SESSION uses
> single quotes around the array element.  In the reference book I am
> using there are no quotes, just something like $_SESSION[first_name].
> I googled a number of discussions and articles and have found examples
> of both methods.
>
> So, my question is, does it matter if one uses the single quotes or no
> quotes as both seem to work?  Are there any security issues or other
> nuances I should be aware of or is the language just forgiving in this
> respect and I could choose either way?


I think I know this one.

Saying array[foo] without quotes is something you can (usually) get away
with but it's deprecated. Bad habit. If you have error reporting set to
report 'notices', PHP will give you a warning about it.

Notice: PHPDocument1 line 5 - Use of undefined constant foo - assumed
'foo'

btw, if you want to embed $array["foo"] within a doble-quoted string, you
can do it protecting it with {}.

echo "Value of \$array["foo"] is now {$array["foo"]}, isn't that
fascinating.";

HTH

---
David Mintz
http://davidmintz.org/
Email: See http://dmintzweb.com/whitelist.php first!

"Y dále p'abajo"

	Tito Rojas







More information about the talk mailing list