For Programmers: Free Programming Magazines  


Home > Archive > PHP PEAR Questions and Answers > January 2005 > String values CS Coding Standards









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author String values CS Coding Standards
bertrand Gugger

2005-01-18, 8:58 pm

Hi QA folks,
So far I can check, PEAR's CS in manual dont give any advice for the
string values.
It gave some discussions about use simple ' or double "
quotation mark.
Obviously PHP kernel loose a little time with double.
But it's quite no debate compared to what it does overall.
Anyway the advice could be:
Simple when it is static (expected never dynamic)
as e.g. an associaive array index as $this->param['setting']
or to initialize a string as $string = '';
Double when content (is expected to) contain variable or escape (\n) to
interpret.
When not obvious (?) then free ' or "
Some people mentioned to choose simple or double once for the whole script.
I will not agree, and I believe it's making no difference for tokenizers.

What should be a rule is the surrounding (brackets) around variables
within double:
never "Hello $name" but "Hello {$name}"
because;
- "Hello $name are you OK ?" could become "Hello $nameare you OK ?"
but "Hello {$name}are you OK ?" still works (I18N)
- or "Hello $name[$i]" should be "Hello {$name[$i]}"
as $name can become $name[$i] or $this->name or ...

It's awfull to type once but value for future maintenance.
This advice is in PHP manual since a long time.
Hope some of you can agree.
Ã_+
--
bertrand Gugger (toggg)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com