2
0

coding_standard.xml 32 KB

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