On 11/18/11 1:44 AM, janroald wrote:

weierophinney wrote:

We typically recommend the second format, or the usage of
heredocs/nowdocs (latter is PHP 5.3 only, though). However, our CS does
not dictate either way.

heredoc/nowdocs I would discourage unless there is a fantastic reason to use them in "library code" for the following reasons:

* it pushes text up against the left margin (in the least the here/nowdoc label)

* if you're trying to beautify your code, you'd be adding additional spaces after a newline (both of which are probably unnecessary)

* you cannot be explicit about your line ending types, it just so happens to include whatever your setting is in your IDE/editor


Many developers find unnecessary concatenation very annoying.
I'm curious why Zend would recommend this practice.
I'm not criticizing, its all just details, I'm just curious if there's any
good reason for it.

Lets take your above example:

Basically, is following allowed?

   1. $sql = "SELECT `id`, `name` FROM `people`
   2.         WHERE `name` = 'Susan'
   3.         ORDER BY `name` ASC ";


Or should it be always like this?

   1. $sql = "SELECT `id`, `name` FROM `people` "
   2.      . "WHERE `name` = 'Susan' "
   3.      . "ORDER BY `name` ASC ";

These two things are not equivalent. In the context of a database connection where whitespace is removed and the SQL is parsed and executed they are equivalent. To a person who wants to push this statement through a logger, they former includes newlines and whitespace that they might otherwise not want in their SQL statement.

So, while it's pretty in the context of your IDE/editor, and in the context of the database it does not care, inside your log file, you'll have unsightly whitespace and newlines.

I, personally, take this a step further and only use double quotes if my intention is to interpolate values, otherwise I stick with a single quote (by seeing a doublequote ("), my brain automatically says to me: "there must be a variable or control character being injected into that somewhere".

Have a good one!
Ralph Schindler

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to