Edit Global Variable?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

whaaa? in xhtml? in php arrays? I'd disagree with both statements....
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

xhtml
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

but doesn't that sort of conflict with php array best practices?

My understanding is this: as long as you enclose your attribute fields in double quotes, using single quotes is fine. How else would you distinguish between an array key string and a constant?

http://ca3.php.net/manual/en/language.t ... rray.donts

On a less-related-note: How's that new job going, btw? You've been quiet lately :-(
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

I think that if you are using arrays in the name of XHTML fields, then the PHP rules don't necessarily apply. I think that if you had a constant defined, then used it as a key name in an XHTML field without quotes, the key would be created as a string (not the constant) due to the way PHP parses out the POST array. Same way as using <input name="thingy[somefunction()]"> would not call a function when the form was posted.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

How else would you distinguish between an array key string and a constant?
yes that is precisely why $array[index] is such bad practice in PHP but you don't have constants in HTML do you. I haven't tested using quotes but I can be certain that they aren't required. My initial concern was that you would have to do this to get access to such post vars:

Code: Select all

<?php
echo $_POST['a']["'foo'"];
?>
<input type="text" name="a['foo']" />
But I'm guessing PHP is clever enough to remove the single quotes first.
On a less-related-note: How's that new job going, btw? You've been quiet lately
Well yes that is what I expected. Things still haven't settled down completely because the guy supposed to be configuring my production and development servers disappeared and now I need to find someone else. I've only had a development server and desktop machine in the last 3 days before that I've been working on my laptop. Actually having a desktop machine is much nicer (got my dual monitors ;)) not just for comfort reasons but also because I now feel like I "belong".

Hopefully I'll be around a bit more in a month's time or so when I'll actually be able to get stuck into some code.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

You are completely correct - I just tried it and PHP sorts it out to make sure no constants get in the way. And all these years I've been using those annoying quotes -- Thanks ole!

Good to see you're getting settled in at work, and that you demanded dual monitors ;-)
Post Reply