Log in

View Full Version : Should variables contain apostrophes in templates?


PinkMilk
03-28-2014, 07:37 AM
Should variables contain apostrophes in templates?

What I mean by this is should they look like this:
<if condition="$post['fieldx'] == 'lala'"> ....
or
<if condition="$post[fieldx] == 'lala'"> ....

both seem to work and I have seen many people use with and without in examples, as well as in the templates themselves, but I would like to know if one is safer then the other, whether it is simply user preference or something else entirely.

Note to mods:
I have accidentally posted this in the wrong forum, it should be in the vB3 General Discussions or vB3 Programming Discussions.

AusPhotography
03-28-2014, 08:32 AM
Zend uses quotes... http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html

PHP doco says use quotes... http://www.php.net/manual/en/language.types.array.php
Array do's and don'ts ?
Why is $foo[bar] wrong? ?

Always use quotes around a string literal array index. For example, $foo['bar'] is correct, while $foo[bar] is not. But why? It is common to encounter this kind of syntax in old scripts:
Read more in link above

PinkMilk
03-29-2014, 09:59 PM
So basically treat as if they where php.

kh99
03-29-2014, 10:17 PM
So basically treat as if they where php.

Right, the stuff in a condition goes pretty much directly into an if statement (although it's checked for function calls that aren't allowed). It's the same in vb4, even though the tag syntax is a little different.

And although you didn't ask about it, variables used in a template (in vb3) go in to a double quoted string, so those rules apply there.