Page 2 of 2
Posted: Thu Feb 22, 2007 10:18 am
by Kieran Huggins
whaaa? in xhtml? in php arrays? I'd disagree with both statements....
Posted: Thu Feb 22, 2007 3:14 pm
by Ollie Saunders
xhtml
Posted: Fri Feb 23, 2007 5:21 am
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

Posted: Fri Feb 23, 2007 7:40 am
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.
Posted: Fri Feb 23, 2007 6:20 pm
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.
Posted: Sat Feb 24, 2007 5:03 am
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
