note 93817 added to function.print
| From: | ChrisWatson at osu1 dot php dot net | Date: | Thu, 01 Oct 2009 08:20:28 +0000 |
| Subject: | note 93817 added to function.print | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161193@lists.php.net to get a copy of this message | ||
mvpetrovich of 2007 could just use single quotes as his string delimiters (see the example in the
current documentation).
It's not ALWAYS appropriate, but generally it is best (the Zend Framework coding standards have
a good take on this). It yields a number of interesting benefits:
1: Nobody will be tempted to write functions to replace backticks or other characters with double
quotes. Such functions may cause a (negligible) loss of efficiency, and maybe other undesired
effects.
2: You will be able to use double quotes without escaping. This is recommended (although not
required) for HTML and XML attributes, as well as quoted text.
3: The script will hit the browser very slightly slightly faster since PHP doesn't have to scan
through the string looking for variables, escaped characters, curly braces or other things.
4: Your code gets ten times easier to read. (as mvpetrovich pointed out)
If, in spite of these four excellent benefits, you really MUST still use double quotes to delimit
boring old string constants (and seriously, why would you?), you could use the slightly less
favourable single quotes as delimiters for most markup languages.
HTML served as HTML will even let you lay out unquoted attributes (yuck).
It should also be noted though that if you are just printing bare strings, you may as well shut off
the php parser. The quickest way to send a string is to write it as plain text, OUTSIDE of the php
tags. This will also make your code look excellent in a lot of syntax highlighters.
There are few disadvantages to doing this, if any. Output buffering still works. All your classes
and objects and includes remain in place. Your script runs faster. World peace is obtained.
----
Server IP: 203.89.181.186
Probable Submitter: 125.236.211.165
----
Manual Page -- http://www.php.net/manual/en/function.print.php
Edit -- https://master.php.net/note/edit/93817
Del: integrated -- https://master.php.net/note/delete/93817/integrated
Del: useless -- https://master.php.net/note/delete/93817/useless
Del: bad code -- https://master.php.net/note/delete/93817/bad+code
Del: spam -- https://master.php.net/note/delete/93817/spam
Del: non-english -- https://master.php.net/note/delete/93817/non-english
Del: in docs -- https://master.php.net/note/delete/93817/in+docs
Del: other reasons-- https://master.php.net/note/delete/93817
Reject -- https://master.php.net/note/reject/93817
Search -- https://master.php.net/manage/user-notes.php