2
0

coding_standard.xml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <appendix id="coding-standard">
  4. <title>Zend Framework Coding Standard for PHP</title>
  5. <sect1 id="coding-standard.overview">
  6. <title>Overview</title>
  7. <sect2 id="coding-standard.overview.scope">
  8. <title>Scope</title>
  9. <para>
  10. This document provides guidelines for code formatting and documentation to
  11. individuals and teams contributing to Zend Framework. Many developers using Zend
  12. Framework have also found these coding standards useful because their code's style
  13. remains consistent with all Zend Framework code. It is also worth noting that it
  14. requires significant effort to fully specify coding standards.
  15. Note: Sometimes developers consider the establishment of a standard more important
  16. than what that standard actually suggests at the most detailed level of design. The
  17. guidelines in the Zend Framework coding standards capture practices that have worked
  18. well on the ZF project. You may modify these standards or use them as is in
  19. accordance with the terms of our
  20. <ulink url="http://framework.zend.com/license">license</ulink>
  21. </para>
  22. <para>
  23. Topics covered in the ZF coding standards include:
  24. <itemizedlist>
  25. <listitem>
  26. <para>PHP File Formatting</para>
  27. </listitem>
  28. <listitem>
  29. <para>Naming Conventions</para>
  30. </listitem>
  31. <listitem>
  32. <para>Coding Style</para>
  33. </listitem>
  34. <listitem>
  35. <para>Inline Documentation</para>
  36. </listitem>
  37. </itemizedlist>
  38. </para>
  39. </sect2>
  40. <sect2 id="coding-standard.overview.goals">
  41. <title>Goals</title>
  42. <para>
  43. Coding standards are important in any development project, but they are particularly
  44. important when many developers are working on the same project. Coding standards
  45. help ensure that the code is high quality, has fewer bugs, and can be easily
  46. maintained.
  47. </para>
  48. </sect2>
  49. </sect1>
  50. <sect1 id="coding-standard.php-file-formatting">
  51. <title>PHP File Formatting</title>
  52. <sect2 id="coding-standard.php-file-formatting.general">
  53. <title>General</title>
  54. <para>
  55. For files that contain only PHP code, the closing tag ("?>") is never permitted. It
  56. is not required by PHP, and omitting it prevents the accidental injection of
  57. trailing white space into the response.
  58. </para>
  59. <para>
  60. <emphasis>IMPORTANT:</emphasis> Inclusion of arbitrary binary data as permitted by
  61. <code>__HALT_COMPILER()</code> is prohibited from PHP files in the Zend Framework
  62. project or files derived from them. Use of this feature is only permitted for some
  63. installation scripts.
  64. </para>
  65. </sect2>
  66. <sect2 id="coding-standard.php-file-formatting.indentation">
  67. <title>Indentation</title>
  68. <para>Indentation should consist of 4 spaces. Tabs are not allowed.</para>
  69. </sect2>
  70. <sect2 id="coding-standard.php-file-formatting.max-line-length">
  71. <title>Maximum Line Length</title>
  72. <para>
  73. The target line length is 80 characters. That is to say, ZF developers should strive
  74. keep each line of their code under 80 characters where possible and practical.
  75. However, longer lines are acceptable in some circumstances. The maximum length of
  76. any line of PHP code is 120 characters.
  77. </para>
  78. </sect2>
  79. <sect2 id="coding-standard.php-file-formatting.line-termination">
  80. <title>Line Termination</title>
  81. <para>
  82. Line termination follows the Unix text file convention. Lines must end with a
  83. single linefeed (LF) character. Linefeed characters are represented as ordinal 10,
  84. or hexadecimal 0x0A.
  85. </para>
  86. <para>
  87. Note: Do not use carriage returns (CR) as is the convention in Apple OS's (0x0D) or
  88. the carriage return/linefeed combination (CRLF) as is standard for the Windows OS
  89. (0x0D, 0x0A).
  90. </para>
  91. </sect2>
  92. </sect1>
  93. <sect1 id="coding-standard.naming-conventions">
  94. <title>Naming Conventions</title>
  95. <sect2 id="coding-standard.naming-conventions.classes">
  96. <title>Classes</title>
  97. <para>
  98. Zend Framework standardizes on a class naming convention whereby the names of the
  99. classes directly map to the directories in which they are stored. The root level
  100. directory of the ZF standard library is the "Zend/" directory, whereas
  101. the root level directory of the ZF extras library is the "ZendX/" directory. All
  102. Zend Framework classes are stored hierarchically under these root directories..
  103. </para>
  104. <para>
  105. Class names may only contain alphanumeric characters. Numbers are permitted
  106. in class names but are discouraged in most cases. Underscores are only permitted in
  107. place of the path separator; the filename "Zend/Db/Table.php" must map to the
  108. class name "Zend_Db_Table".
  109. </para>
  110. <para>
  111. If a class name is comprised of more than one word, the first letter of each new
  112. word must be capitalized. Successive capitalized letters are not allowed, e.g.
  113. a class "Zend_PDF" is not allowed while "Zend_Pdf" is acceptable.
  114. </para>
  115. <para>
  116. These conventions define a pseudo-namespace mechanism for Zend Framework. Zend
  117. Framework will adopt the PHP namespace feature when it becomes available and is
  118. feasible for our developers to use in their applications.
  119. </para>
  120. <para>
  121. See the class names in the standard and extras libraries for examples of this
  122. classname convention. <emphasis>IMPORTANT:</emphasis> Code that must be deployed
  123. alongside ZF libraries but is not part of the standard or extras libraries (e.g.
  124. application code or libraries that are not distributed by Zend) must never start
  125. with "Zend_" or "ZendX_".
  126. </para>
  127. </sect2>
  128. <sect2 id="coding-standard.naming-conventions.filenames">
  129. <title>Filenames</title>
  130. <para>
  131. For all other files, only alphanumeric characters, underscores, and the dash
  132. character ("-") are permitted. Spaces are strictly prohibited.
  133. </para>
  134. <para>
  135. Any file that contains PHP code should end with the extension ".php", with the
  136. notable exception of view scripts. The following examples show acceptable filenames
  137. for Zend Framework classes:
  138. <programlisting language="php"><![CDATA[
  139. Zend/Db.php
  140. Zend/Controller/Front.php
  141. Zend/View/Helper/FormRadio.php
  142. ]]></programlisting>
  143. File names must map to class names as described above.
  144. </para>
  145. </sect2>
  146. <sect2 id="coding-standard.naming-conventions.functions-and-methods">
  147. <title>Functions and Methods</title>
  148. <para>
  149. Function names may only contain alphanumeric characters. Underscores are not
  150. permitted. Numbers are permitted in function names but are discouraged in most
  151. cases.
  152. </para>
  153. <para>
  154. Function names must always start with a lowercase letter. When a function name
  155. consists of more than one word, the first letter of each new word must be
  156. capitalized. This is commonly called "camelCase" formatting.
  157. </para>
  158. <para>
  159. Verbosity is generally encouraged. Function names should be as verbose as is
  160. practical to fully describe their purpose and behavior.
  161. </para>
  162. <para>
  163. These are examples of acceptable names for functions:
  164. <programlisting language="php"><![CDATA[
  165. filterInput()
  166. getElementById()
  167. widgetFactory()
  168. ]]></programlisting>
  169. </para>
  170. <para>
  171. For object-oriented programming, accessors for instance or static variables should
  172. always be prefixed with "get" or "set". In implementing design patterns, such as the
  173. singleton or factory patterns, the name of the method should contain the pattern
  174. name where practical to more thoroughly describe behavior.
  175. </para>
  176. <para>
  177. For methods on objects that are declared with the "private" or "protected" modifier,
  178. the first character of the method name must be an underscore. This is the only
  179. acceptable application of an underscore in a method name. Methods declared "public"
  180. should never contain an underscore.
  181. </para>
  182. <para>
  183. Functions in the global scope (a.k.a "floating functions") are permitted but
  184. discouraged in most cases. Consider wrapping these functions in a static class.
  185. </para>
  186. </sect2>
  187. <sect2 id="coding-standard.naming-conventions.variables">
  188. <title>Variables</title>
  189. <para>
  190. Variable names may only contain alphanumeric characters. Underscores are not
  191. permitted. Numbers are permitted in variable names but are discouraged in most
  192. cases.
  193. </para>
  194. <para>
  195. For instance variables that are declared with the "private" or "protected" modifier,
  196. the first character of the variable name must be a single underscore. This is the
  197. only acceptable application of an underscore in a variable name. Member variables
  198. declared "public" should never start with an underscore.
  199. </para>
  200. <para>
  201. As with function names (see section 3.3) variable names must always start with a
  202. lowercase letter and follow the "camelCaps" capitalization convention.
  203. </para>
  204. <para>
  205. Verbosity is generally encouraged. Variables should always be as verbose as
  206. practical to describe the data that the developer intends to store in them. Terse
  207. variable names such as "$i" and "$n" are discouraged for all but the smallest loop
  208. contexts. If a loop contains more than 20 lines of code, the index variables should
  209. have more descriptive names.
  210. </para>
  211. </sect2>
  212. <sect2 id="coding-standard.naming-conventions.constants">
  213. <title>Constants</title>
  214. <para>
  215. Constants may contain both alphanumeric characters and underscores. Numbers are
  216. permitted in constant names.
  217. </para>
  218. <para>
  219. All letters used in a constant name must be capitalized, while all words in a
  220. constant name must be separated by underscore characters.
  221. </para>
  222. <para>
  223. For example, <code>EMBED_SUPPRESS_EMBED_EXCEPTION</code> is permitted but
  224. <code>EMBED_SUPPRESSEMBEDEXCEPTION</code> is not.
  225. </para>
  226. <para>
  227. Constants must be defined as class members with the "const" modifier. Defining
  228. constants in the global scope with the "define" function is permitted but strongly
  229. discouraged.
  230. </para>
  231. </sect2>
  232. </sect1>
  233. <sect1 id="coding-standard.coding-style">
  234. <title>Coding Style</title>
  235. <sect2 id="coding-standard.coding-style.php-code-demarcation">
  236. <title>PHP Code Demarcation</title>
  237. <para>
  238. PHP code must always be delimited by the full-form, standard PHP tags:
  239. <programlisting language="php"><![CDATA[
  240. <?php
  241. ?>
  242. ]]></programlisting>
  243. </para>
  244. <para>
  245. Short tags are never allowed. For files containing only PHP code, the closing tag
  246. must always be omitted (See <xref
  247. linkend="coding-standard.php-file-formatting.general" />).
  248. </para>
  249. </sect2>
  250. <sect2 id="coding-standard.coding-style.strings">
  251. <title>Strings</title>
  252. <sect3 id="coding-standard.coding-style.strings.literals">
  253. <title>String Literals</title>
  254. <para>
  255. When a string is literal (contains no variable substitutions), the apostrophe or
  256. "single quote" should always be used to demarcate the string:
  257. <programlisting language="php"><![CDATA[
  258. $a = 'Example String';
  259. ]]></programlisting>
  260. </para>
  261. </sect3>
  262. <sect3 id="coding-standard.coding-style.strings.literals-containing-apostrophes">
  263. <title>String Literals Containing Apostrophes</title>
  264. <para>
  265. When a literal string itself contains apostrophes, it is permitted to demarcate
  266. the string with quotation marks or "double quotes". This is especially useful
  267. for SQL statements:
  268. <programlisting language="php"><![CDATA[
  269. $sql = "SELECT `id`, `name` from `people` "
  270. . "WHERE `name`='Fred' OR `name`='Susan'";
  271. ]]></programlisting>
  272. This syntax is preferred over escaping apostrophes as it is much easier to read.
  273. </para>
  274. </sect3>
  275. <sect3 id="coding-standard.coding-style.strings.variable-substitution">
  276. <title>Variable Substitution</title>
  277. <para>
  278. Variable substitution is permitted using either of these forms:
  279. <programlisting language="php"><![CDATA[
  280. $greeting = "Hello $name, welcome back!";
  281. $greeting = "Hello {$name}, welcome back!";
  282. ]]></programlisting>
  283. </para>
  284. <para>
  285. For consistency, this form is not permitted:
  286. <programlisting language="php"><![CDATA[
  287. $greeting = "Hello ${name}, welcome back!";
  288. ]]></programlisting>
  289. </para>
  290. </sect3>
  291. <sect3 id="coding-standard.coding-style.strings.string-concatenation">
  292. <title>String Concatenation</title>
  293. <para>
  294. Strings must be concatenated using the "." operator. A space must always
  295. be added before and after the "." operator to improve readability:
  296. <programlisting language="php"><![CDATA[
  297. $company = 'Zend' . ' ' . 'Technologies';
  298. ]]></programlisting>
  299. </para>
  300. <para>
  301. When concatenating strings with the "." operator, it is encouraged to
  302. break the statement into multiple lines to improve readability. In these
  303. cases, each successive line should be padded with white space such that the
  304. "."; operator is aligned under the "=" operator:
  305. <programlisting language="php"><![CDATA[
  306. $sql = "SELECT `id`, `name` FROM `people` "
  307. . "WHERE `name` = 'Susan' "
  308. . "ORDER BY `name` ASC ";
  309. ]]></programlisting>
  310. </para>
  311. </sect3>
  312. </sect2>
  313. <sect2 id="coding-standard.coding-style.arrays">
  314. <title>Arrays</title>
  315. <sect3 id="coding-standard.coding-style.arrays.numerically-indexed">
  316. <title>Numerically Indexed Arrays</title>
  317. <para>Negative numbers are not permitted as indices.</para>
  318. <para>
  319. An indexed array may start with any non-negative number, however
  320. all base indices besides 0 are discouraged.
  321. </para>
  322. <para>
  323. When declaring indexed arrays with the <type>Array</type> function, a trailing
  324. space must be added after each comma delimiter to improve readability:
  325. <programlisting language="php"><![CDATA[
  326. $sampleArray = array(1, 2, 3, 'Zend', 'Studio');
  327. ]]></programlisting>
  328. </para>
  329. <para>
  330. It is permitted to declare multi-line indexed arrays using the "array"
  331. construct. In this case, each successive line must be padded with spaces such
  332. that beginning of each line is aligned:
  333. <programlisting language="php"><![CDATA[
  334. $sampleArray = array(1, 2, 3, 'Zend', 'Studio',
  335. $a, $b, $c,
  336. 56.44, $d, 500);
  337. ]]></programlisting>
  338. </para>
  339. </sect3>
  340. <sect3 id="coding-standard.coding-style.arrays.associative">
  341. <title>Associative Arrays</title>
  342. <para>
  343. When declaring associative arrays with the <type>Array</type> construct,
  344. breaking the statement into multiple lines is encouraged. In this case, each
  345. successive line must be padded with white space such that both the keys and the
  346. values are aligned:
  347. <programlisting language="php"><![CDATA[
  348. $sampleArray = array('firstKey' => 'firstValue',
  349. 'secondKey' => 'secondValue');
  350. ]]></programlisting>
  351. </para>
  352. </sect3>
  353. </sect2>
  354. <sect2 id="coding-standard.coding-style.classes">
  355. <title>Classes</title>
  356. <sect3 id="coding-standard.coding-style.classes.declaration">
  357. <title>Class Declaration</title>
  358. <para>
  359. Classes must be named according to Zend Framework's naming conventions.
  360. </para><para>
  361. The brace should always be written on the line underneath the class name.
  362. </para><para>
  363. Every class must have a documentation block that conforms to the PHPDocumentor
  364. standard.
  365. </para><para>
  366. All code in a class must be indented with four spaces.
  367. </para><para>
  368. Only one class is permitted in each PHP file.
  369. </para><para>
  370. Placing additional code in class files is permitted but discouraged.
  371. In such files, two blank lines must separate the class from any additional PHP
  372. code in the class file.
  373. </para><para>
  374. The following is an example of an acceptable class declaration:
  375. <programlisting language="php"><![CDATA[
  376. /**
  377. * Documentation Block Here
  378. */
  379. class SampleClass
  380. {
  381. // all contents of class
  382. // must be indented four spaces
  383. }
  384. ]]></programlisting>
  385. </para>
  386. </sect3>
  387. <sect3 id="coding-standard.coding-style.classes.member-variables">
  388. <title>Class Member Variables</title>
  389. <para>
  390. Member variables must be named according to Zend Framework's variable naming
  391. conventions.
  392. </para>
  393. <para>
  394. Any variables declared in a class must be listed at the top of the class, above
  395. the declaration of any methods.
  396. </para>
  397. <para>
  398. The <code>var</code> construct is not permitted. Member variables always declare
  399. their visibility by using one of the <code>private</code>,
  400. <code>protected</code>, or <code>public</code> modifiers. Giving access to
  401. member variables directly by declaring them as public is permitted but
  402. discouraged in favor of accessor methods (set/get).
  403. </para>
  404. </sect3>
  405. </sect2>
  406. <sect2 id="coding-standard.coding-style.functions-and-methods">
  407. <title>Functions and Methods</title>
  408. <sect3 id="coding-standard.coding-style.functions-and-methods.declaration">
  409. <title>Function and Method Declaration</title>
  410. <para>
  411. Functions must be named according to the Zend Framework function naming
  412. conventions.
  413. </para>
  414. <para>
  415. Methods inside classes must always declare their visibility by using
  416. one of the <code>private</code>, <code>protected</code>,
  417. or <code>public</code> modifiers.
  418. </para>
  419. <para>
  420. As with classes, the brace should always be written on the line underneath the
  421. function name. Space between the function name and the opening parenthesis for
  422. the arguments is not permitted.
  423. </para>
  424. <para>
  425. Functions in the global scope are strongly discouraged.
  426. </para>
  427. <para>
  428. The following is an example of an acceptable function declaration in a class:
  429. <programlisting language="php"><![CDATA[
  430. /**
  431. * Documentation Block Here
  432. */
  433. class Foo
  434. {
  435. /**
  436. * Documentation Block Here
  437. */
  438. public function bar()
  439. {
  440. // all contents of function
  441. // must be indented four spaces
  442. }
  443. }
  444. ]]></programlisting>
  445. </para>
  446. <para>
  447. <emphasis>NOTE:</emphasis> Pass-by-reference is the only parameter passing
  448. mechanism permitted in a method declaration.
  449. <programlisting language="php"><![CDATA[
  450. /**
  451. * Documentation Block Here
  452. */
  453. class Foo
  454. {
  455. /**
  456. * Documentation Block Here
  457. */
  458. public function bar(&$baz)
  459. {}
  460. }
  461. ]]></programlisting>
  462. </para>
  463. <para>
  464. Call-time pass-by-reference is strictly prohibited.
  465. </para>
  466. <para>
  467. The return value must not be enclosed in parentheses. This can hinder
  468. readability, in additional to breaking code if a method is later changed to
  469. return by reference.
  470. <programlisting language="php"><![CDATA[
  471. /**
  472. * Documentation Block Here
  473. */
  474. class Foo
  475. {
  476. /**
  477. * WRONG
  478. */
  479. public function bar()
  480. {
  481. return($this->bar);
  482. }
  483. /**
  484. * RIGHT
  485. */
  486. public function bar()
  487. {
  488. return $this->bar;
  489. }
  490. }
  491. ]]></programlisting>
  492. </para>
  493. </sect3>
  494. <sect3 id="coding-standard.coding-style.functions-and-methods.usage">
  495. <title>Function and Method Usage</title>
  496. <para>
  497. Function arguments should be separated by a single trailing space after the
  498. comma delimiter. The following is an example of an acceptable invocation of a
  499. function that takes three arguments:
  500. <programlisting language="php"><![CDATA[
  501. threeArguments(1, 2, 3);
  502. ]]></programlisting>
  503. </para>
  504. <para>
  505. Call-time pass-by-reference is strictly prohibited. See the function
  506. declarations section for the proper way to pass function arguments by-reference.
  507. </para>
  508. <para>
  509. In passing arrays as arguments to a function, the function call may include the
  510. "array" hint and may be split into multiple lines to improve readability. In
  511. such cases, the normal guidelines for writing arrays still apply:
  512. <programlisting language="php"><![CDATA[
  513. threeArguments(array(1, 2, 3), 2, 3);
  514. threeArguments(array(1, 2, 3, 'Zend', 'Studio',
  515. $a, $b, $c,
  516. 56.44, $d, 500), 2, 3);
  517. ]]></programlisting>
  518. </para>
  519. </sect3>
  520. </sect2>
  521. <sect2 id="coding-standard.coding-style.control-statements">
  522. <title>Control Statements</title>
  523. <sect3 id="coding-standard.coding-style.control-statements.if-else-elseif">
  524. <title>If/Else/Elseif</title>
  525. <para>
  526. Control statements based on the <code>if</code> and <code>elseif</code>
  527. constructs must have a single space before the opening parenthesis of the
  528. conditional and a single space after the closing parenthesis.
  529. </para>
  530. <para>
  531. Within the conditional statements between the parentheses, operators must be
  532. separated by spaces for readability. Inner parentheses are encouraged to improve
  533. logical grouping for larger conditional expressions.
  534. </para>
  535. <para>
  536. The opening brace is written on the same line as the conditional statement. The
  537. closing brace is always written on its own line. Any content within the braces
  538. must be indented using four spaces.
  539. <programlisting language="php"><![CDATA[
  540. if ($a != 2) {
  541. $a = 2;
  542. }
  543. ]]></programlisting>
  544. </para>
  545. <para>
  546. For "if" statements that include "elseif" or "else", the formatting conventions
  547. are similar to the "if" construct. The following examples demonstrate proper
  548. formatting for "if" statements with "else" and/or "elseif" constructs:
  549. <programlisting language="php"><![CDATA[
  550. if ($a != 2) {
  551. $a = 2;
  552. } else {
  553. $a = 7;
  554. }
  555. if ($a != 2) {
  556. $a = 2;
  557. } elseif ($a == 3) {
  558. $a = 4;
  559. } else {
  560. $a = 7;
  561. }
  562. ]]></programlisting>
  563. PHP allows statements to be written without braces in some circumstances. This
  564. coding standard makes no differentiation- all "if", "elseif" or "else"
  565. statements must use braces.
  566. </para>
  567. <para>
  568. Use of the "elseif" construct is permitted but strongly discouraged in favor of
  569. the "else if" combination.
  570. </para>
  571. </sect3>
  572. <sect3 id="coding-standards.coding-style.control-statements.switch">
  573. <title>Switch</title>
  574. <para>
  575. Control statements written with the "switch" statement must have a single space
  576. before the opening parenthesis of the conditional statement and after the
  577. closing parenthesis.
  578. </para>
  579. <para>
  580. All content within the "switch" statement must be indented using four spaces.
  581. Content under each "case" statement must be indented using an additional four
  582. spaces.
  583. </para>
  584. <programlisting language="php"><![CDATA[
  585. switch ($numPeople) {
  586. case 1:
  587. break;
  588. case 2:
  589. break;
  590. default:
  591. break;
  592. }
  593. ]]></programlisting>
  594. <para>
  595. The construct <code>default</code> should never be omitted from a
  596. <code>switch</code> statement.
  597. </para>
  598. <para>
  599. <emphasis>NOTE:</emphasis> It is sometimes useful to write a <code>case</code>
  600. statement which falls through to the next case by not including a
  601. <code>break</code> or <code>return</code> within that case. To distinguish these
  602. cases from bugs, any <code>case</code> statement where <code>break</code> or
  603. <code>return</code> are omitted should contain a comment indicating that the
  604. break was intentionally omitted.
  605. </para>
  606. </sect3>
  607. </sect2>
  608. <sect2 id="coding-standards.inline-documentation">
  609. <title>Inline Documentation</title>
  610. <sect3 id="coding-standards.inline-documentation.documentation-format">
  611. <title>Documentation Format</title>
  612. <para>
  613. All documentation blocks ("docblocks") must be compatible with the phpDocumentor
  614. format. Describing the phpDocumentor format is beyond the scope of this
  615. document. For more information, visit: <ulink
  616. url="http://phpdoc.org/">http://phpdoc.org/</ulink>
  617. </para>
  618. <para>
  619. All class files must contain a "file-level" docblock at the top of each file and
  620. a "class-level" docblock immediately above each class. Examples of such
  621. docblocks can be found below.
  622. </para>
  623. </sect3>
  624. <sect3 id="coding-standards.inline-documentation.files">
  625. <title>Files</title>
  626. <para>
  627. Every file that contains PHP code must have a docblock at the top of the file
  628. that contains these phpDocumentor tags at a minimum:
  629. <programlisting language="php"><![CDATA[
  630. /**
  631. * Short description for file
  632. *
  633. * Long description for file (if any)...
  634. *
  635. * LICENSE: Some license information
  636. *
  637. * @copyright 2008 Zend Technologies
  638. * @license http://framework.zend.com/license BSD License
  639. * @version $Id:$
  640. * @link http://framework.zend.com/package/PackageName
  641. * @since File available since Release 1.5.0
  642. */
  643. ]]></programlisting>
  644. </para>
  645. </sect3>
  646. <sect3 id="coding-standards.inline-documentation.classes">
  647. <title>Classes</title>
  648. <para>
  649. Every class must have a docblock that contains these phpDocumentor tags at a
  650. minimum:
  651. <programlisting language="php"><![CDATA[
  652. /**
  653. * Short description for class
  654. *
  655. * Long description for class (if any)...
  656. *
  657. * @copyright 2008 Zend Technologies
  658. * @license http://framework.zend.com/license BSD License
  659. * @version Release: @package_version@
  660. * @link http://framework.zend.com/package/PackageName
  661. * @since Class available since Release 1.5.0
  662. * @deprecated Class deprecated in Release 2.0.0
  663. */
  664. ]]></programlisting>
  665. </para>
  666. </sect3>
  667. <sect3 id="coding-standards.inline-documentation.functions">
  668. <title>Functions</title>
  669. <para>
  670. Every function, including object methods, must have a docblock that contains at a
  671. minimum:
  672. <itemizedlist>
  673. <listitem><para>A description of the function</para></listitem>
  674. <listitem><para>All of the arguments</para></listitem>
  675. <listitem><para>All of the possible return values</para></listitem>
  676. </itemizedlist>
  677. </para>
  678. <para>
  679. It is not necessary to use the "@access" tag because the access level is already
  680. known from the "public", "private", or "protected" modifier used to declare the
  681. function.
  682. </para>
  683. <para>
  684. If a function/method may throw an exception, use @throws for all known exception
  685. classes:
  686. <programlisting language="php"><![CDATA[
  687. @throws exceptionclass [description]
  688. ]]></programlisting>
  689. </para>
  690. </sect3>
  691. </sect2>
  692. </sect1>
  693. </appendix>
  694. <!--
  695. vim:se ts=4 sw=4 et:
  696. -->