coding_standard.xml 31 KB

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