vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Should variables contain apostrophes in templates? (https://vborg.vbsupport.ru/showthread.php?t=309976)

PinkMilk 03-28-2014 07:37 AM

Should variables contain apostrophes in templates?
 
Should variables contain apostrophes in templates?

What I mean by this is should they look like this:
Code:

<if condition="$post['fieldx'] == 'lala'"> ....
or
Code:

<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.1...ing-style.html

PHP doco says use quotes... http://www.php.net/manual/en/language.types.array.php
Quote:

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

Quote:

Originally Posted by PinkMilk (Post 2490330)
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.


All times are GMT. The time now is 05:30 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01172 seconds
  • Memory Usage 1,719KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete