coding_standard.xml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <appendix id="coding-standard">
  2. <title>Zend Framework PHP Coding Standard</title>
  3. <sect1 id="coding-standard.overview">
  4. <title>Overview</title>
  5. <sect2 id="coding-standard.overview.scope">
  6. <title>Scope</title>
  7. <para>
  8. 본 문서는 젠드 프래임워크를 개발하는 개발자 개인과 팀 혹은 단체에게 가이드라인과 리소스를 제공하는 문서입니다. 본문서에서는 다음의 주제들이 다루어 집니다.:
  9. <itemizedlist>
  10. <listitem>
  11. <para>PHP 파일의 포멧 형식</para>
  12. </listitem>
  13. <listitem>
  14. <para>이름 규칙</para>
  15. </listitem>
  16. <listitem>
  17. <para>코딩 스타일</para>
  18. </listitem>
  19. <listitem>
  20. <para>Inline Documentation</para>
  21. </listitem>
  22. </itemizedlist>
  23. </para>
  24. </sect2>
  25. <sect2 id="coding-standard.overview.goals">
  26. <title>목표</title>
  27. <para>
  28. 바람직한 코딩 규약은 어떤 프로젝트에서나 중요한 요소로 작용합니다. 특히 동일 프로젝트를 여러명의 개발자가 동시에 작업할경우 더더욱 중요합니다. 코딩의 표준 규약은 소스 코드 자체의 높은 품질과, 적은 버그 그리고 손쉬운 유지관리에 많은 도움을 줍니다.
  29. </para>
  30. </sect2>
  31. </sect1>
  32. <sect1 id="coding-standard.php-file-formatting">
  33. <title>PHP 파일의 포멧</title>
  34. <sect2 id="coding-standard.php-file-formatting.general">
  35. <title>일반 사항</title>
  36. <para>
  37. 오직 PHP코드만을 포함한 파일에서는, 코드의 맺음 태그("?>")가 절대 허용되지 않습니다. 이는 PHP에 의해서 허용되지 않는 부분입니다. 맺음 태그를 포함하지 않는 것은 공백문자열이 아웃풋된 결과에 삽입되지 않도록 하기 위한 조취입니다.
  38. </para>
  39. <para>
  40. <emphasis>주의:</emphasis> <code>__HALT_COMPILER()</code>에 의해서 생성된 임의적인 바이너리 데이터의 포함은 젠드 프래임워크 php파일 혹은 젠드 프래임워크에 의해 생성된 모든 파일에서 허용되지 않습니다. 이러한 기능의 사용은 특별한 설치 스크립트에 의해서만 허용됩니다.
  41. </para>
  42. </sect2>
  43. <sect2 id="coding-standard.php-file-formatting.indentation">
  44. <title>인덴트</title>
  45. <para>탭(Tab)이 아닌 4개의 공백문자(space)를 이용해 주십시오.</para>
  46. </sect2>
  47. <sect2 id="coding-standard.php-file-formatting.max-line-length">
  48. <title>최대 허용 라인 줄수</title>
  49. <para>
  50. 한줄에 허용되는 글자수는 80글자를 기준으로 삼습니다. 개발자는 가능한한 한줄안에 80컬럼내의 문자가 삽입되도록 해주십시요. 그러나 그 이상의 글자도 가능은 합니다. PHP 코드의 최대 허용 글자수는 120 캐릭터입니다.
  51. </para>
  52. </sect2>
  53. <sect2 id="coding-standard.php-file-formatting.line-termination">
  54. <title>라인 터미네이션(줄바꾸기)</title>
  55. <para>
  56. 라인 터미네이션(줄바꾸기)은 유닉스 텍스트 파일의 그것과 동일합니다. 라인은 라인피드(LF)로 항상 끝나야 합니다. 라인피드(Linefeeds)는 오디날(ordinal) 10 혹은 16진수로 0x0A로 표현합니다.
  57. </para>
  58. <para>
  59. 메킨토시 컴퓨터에서 쓰이는 캐리지 리턴(CR,0x0D)은 이용하지 마십시오.
  60. </para>
  61. <para>
  62. 윈도우 컴퓨터에서 쓰이는 return/linefeed 조합(CRLF,0x0D, 0x0A)은 이용하지 마십시오.
  63. </para>
  64. </sect2>
  65. </sect1>
  66. <sect1 id="coding-standard.naming-conventions">
  67. <title>이름 규칙</title>
  68. <sect2 id="coding-standard.naming-conventions.classes">
  69. <title>클라스</title>
  70. <para>
  71. 젠드 프래임워크는 클라스 이름과 그 클래스가 존재하는 디렉토리의 위치가 상호 매칭되는 구조를 가지고 있습니다.젠드 프래임워크의 최상위 디렉토리는 "Zend/"디렉토리이며 모든 클라스들은 이 아래에 계층적으로 위치하게 됩니다.
  72. </para>
  73. <para>
  74. 클라스 이름은 오직 알파벳만 포함할수 있습니다. 클라스 이름에 숫자가 허용은 되지만 권장되지는 않습니다. 밑줄(_)은 경로 구분자를 대체하는 역활로만 쓰입니다. -- 파일이름 "Zend/Db/Table.php"는 클라스 이름 "Zend_Db_Table"와 매칭이 되어야 합니다.
  75. </para>
  76. <para>
  77. 만약 클라스 이름이 하나 이상의 단어로 이루어진경우, 각 단어의 첫번째 단어는 대문가 되어야 합니다. 하지만 클라스이름에서 연이은 대문자의 조합은 허용되지 않습니다. 예를 들면 "Zend_PDF"는 허용되지 않는 형태이고 "Zend_Pdf"는 허용되는 형태입니다.
  78. </para>
  79. <para>
  80. 프레임워크와 함꼐 배포되어지는 젠드사 혹은 젠드사의 파트너 회사들의 클라스들은 항상 "Zend_" 라는 문구로 시작되며 "Zend/" 디렉토리 아래에 계층적으로 위치하게 됩니다.
  81. </para>
  82. <para>
  83. 클라스 명으로 허용되는 예들:
  84. <programlisting role="php"><![CDATA[
  85. Zend_Db
  86. Zend_View
  87. Zend_View_Helper]]>
  88. </programlisting>
  89. <emphasis>주의:</emphasis>프레임워크와 연동은 되지만 프레임워크의 일부가 아닌 코드들은 (젠드나 젠트 파트너사 가 아닌 일반 사용자에 의해 제작된 코드) "Zend_"라는 이름으로 시작해서는 절대 안됩니다.
  90. </para>
  91. </sect2>
  92. <sect2 id="coding-standard.naming-conventions.interfaces">
  93. <title>인터페이스</title>
  94. <para>
  95. 인터페이스 클라스들은 다른 클라스들과 마찬가지의 이름 규칙을 이용합니다. 단 인터페이스들은 그 클라스 이름의 마지막이 "Interface"로 끝나야 합니다. 예:
  96. <programlisting role="php"><![CDATA[
  97. Zend_Log_Adapter_Interface
  98. Zend_Controller_Dispatcher_Interface]]>
  99. </programlisting>
  100. </para>
  101. </sect2>
  102. <sect2 id="coding-standard.naming-conventions.filenames">
  103. <title>파일이름</title>
  104. <para>
  105. 그 외에 모든 파일들은 알파벳과 밑줄(_) 그리고 대쉬(-)만이 그 이름에 허용됩니다. 공백문자는 허용되지 않습니다.
  106. </para>
  107. <para>
  108. 어떠한 파일이던 PHP 코드를 포함하고 있는 파일들은 ".php"의 확장자를 가져야 합니다. 다음의 예제들은 윗 섹션에서 예를 들었던 클라스들이 포함된 허용가능한 파일이름들입니다:
  109. <programlisting role="php"><![CDATA[
  110. Zend/Db.php
  111. Zend/Controller/Front.php
  112. Zend/View/Helper/FormRadio.php]]>
  113. </programlisting>
  114. 파일이름들은 반드시 위에 기술된 대로 클라스 이름에 매핑되어야 합니다.
  115. </para>
  116. </sect2>
  117. <sect2 id="coding-standard.naming-conventions.functions-and-methods">
  118. <title>함수(Function)와 메소드들</title>
  119. <para>
  120. Function의 이름들은 알파벳만이 허용됩니다. 밑줄(_)은 허용되지 않습니다. Function이름에 숫자는 허용이 되나 권장되는 사항은 아닙니다.
  121. </para>
  122. <para>
  123. Function 이름들은 항상 소문자로 시작하여야 합니다. Function 이름이 하나의 문자 이상으로 이루어져 있을경우 새로 덧붙여지는 새 단어의 첫글자는 대문자야여 합니다. 이는 일반적으로 "camelCaps" 방식이라고 불리어 집니다.
  124. </para>
  125. <para>
  126. Function 이름을 그 기능을 짐작할수 있게 만드는것은 권장됩니다. 그 기능을 짐작할수 있게 지어진 Function의 이름은 코드를 이해하는데 실질적으로 많은 도움이 됩니다.
  127. </para>
  128. <para>
  129. 다음은 권장되는 Function 이름들의 예입니다:
  130. <programlisting role="php"><![CDATA[
  131. filterInput()
  132. getElementById()
  133. widgetFactory()]]>
  134. </programlisting>
  135. </para>
  136. <para>
  137. 객체 지형 언어에서 객제에 대한 접근자들은 항상 "get"이나 "set"이라는 접두어를 가지고 있습니다. Singleton 이나 Factory pattern등의 디자인 패턴을 이용하는 경우, 메소드 이름들은 해당 패턴들을 좀더 쉽게 인식할수있는 패턴 이름을 포함하고 있어야 합니다.
  138. </para>
  139. <para>
  140. 전역(global scope, floating functions) 함수는 허용이 되지만 권장되지 않습니다. 하나 Function은 하나의 스타틱 클라스안에서만 이루어지기를 권장합니다.
  141. </para>
  142. </sect2>
  143. <sect2 id="coding-standard.naming-conventions.variables">
  144. <title>변수</title>
  145. <para>
  146. 변수명은 오직 알파멧만 허용이 됩니다. 밑줄(_)은 허용되지 않습니다. 변수명에 숫자는 허용이 되지만 권장되지는 않습니다.
  147. </para>
  148. <para>
  149. "private"나 "protected"로 선언된 클라스 멤버 변수들은 그 이름의 첫 시작이 하나의 밑줄(_)로 시작되어야 합니다. 이는 Function 이름에서 밑줄이 허용되는 유일한 경우입니다. "Publice"으로 정의된 맴버 변수들은 밑줄(_)로 시작되어서는 안됩니다.
  150. </para>
  151. <para>
  152. Function 이름과 같이 (섹션 3.3을 참고) 변수의 이름들은 소문자로 시작되면 "camelCaps"의 대소문자 규정을 따릅니다.
  153. </para>
  154. <para>
  155. 그 특성을 나타내는 설명구의 이름은 권장됩니다. 변수들은 가능한한 그 역활을 나타내는 쪽으로 이름지어져야 합니다. "$i" 나 "$n"과 같은 단순한 변수명은 단순한 반복문에서를 제외하고는 권장되지 않습니다. 만약 반복구문이 20줄 이상의 크기라면 변수의 이름은 좀더 그 역활이 기술되어있는 쪽으로 지어져야 합니다.
  156. </para>
  157. </sect2>
  158. <sect2 id="coding-standard.naming-conventions.constants">
  159. <title>상수</title>
  160. <para>
  161. 상수의 이름들은 알바벳 캐릭터와 밑줄(_)을 동시에 포함할수 있습니다. 상수의 이름에 숫자는 허용됩니다.
  162. </para>
  163. <para>
  164. 상수의 이름은 반드시 대문자로 이루어져야 합니다.
  165. </para>
  166. <para>
  167. 시각적으로 좀더 쉬운 해독을 위하여, 상수의 단어들은 밑줄(_)로 나뉘어 져야 합니다. 예를 들어 <code>EMBED_SUPPRESS_EMBED_EXCEPTION</code>은 허용되어 지나 <code>EMBED_SUPPRESSEMBEDEXCEPTION</code>은 허용되지 않습니다.
  168. </para>
  169. <para>
  170. 상수는 반드시 "const" 지시어를 써서 클라스 맴버로 정의되어야 합니다. 전역변수로서 "define" 지시어와 함께 정의된 상수는 가능은 하나 권장되지 않습니다.
  171. </para>
  172. </sect2>
  173. </sect1>
  174. <sect1 id="coding-standard.coding-style">
  175. <title>코딩 스타일</title>
  176. <sect2 id="coding-standard.coding-style.php-code-demarcation">
  177. <title>PHP 코드의 구분</title>
  178. <para>
  179. PHP 코드는 항상 완젹한 표준 PHP 테그의 형태로 구분지어져야 합니다:
  180. <programlisting role="php"><![CDATA[<?php
  181. ?>]]></programlisting>
  182. </para>
  183. <para>
  184. 테그의 단축형은 허용되지 않습니다. 오직 PHP 코드만을 포함하고 있는 파일의 경우, 맺음 테그는 반드시 생략하여야 합니다.(See <xref linkend="coding-standard.php-file-formatting.general" />).
  185. </para>
  186. </sect2>
  187. <sect2 id="coding-standard.coding-style.strings">
  188. <title>문자열</title>
  189. <sect3 id="coding-standard.coding-style.strings.literals">
  190. <title>단순 문자열</title>
  191. <para>
  192. 어떠한 변수도 포함하지 않은 단순 문자열의 경우 단따옴표 혹은 어퍼스트로피를 이용하여 문자열을 구별지어야 합니다:
  193. <programlisting role="php"><![CDATA[
  194. $a = 'Example String';]]>
  195. </programlisting>
  196. </para>
  197. </sect3>
  198. <sect3 id="coding-standard.coding-style.strings.literals-containing-apostrophes">
  199. <title>단따옴표를 포함한 문자열</title>
  200. <para>
  201. 문자열 자체가 어퍼스트로피(단따옴표)를 포함하고 있는 경우, "상따옴표"를 이용하여 구별되어 질수 있습니다. 이는 특히 SQL 구문의 처리시 유용합니다:
  202. <programlisting role="php"><![CDATA[
  203. $sql = "SELECT `id`, `name` from `people` WHERE `name`='Fred' OR `name`='Susan'";]]>
  204. </programlisting>
  205. The above syntax is preferred over escaping apostrophes.
  206. </para>
  207. </sect3>
  208. <sect3 id="coding-standard.coding-style.strings.variable-substitution">
  209. <title>변수의 치환</title>
  210. <para>
  211. 변수의 치환은 다음 두가지 방법으로 허용됩니다.:
  212. <programlisting role="php"><![CDATA[
  213. $greeting = "Hello $name, welcome back!";
  214. $greeting = "Hello {$name}, welcome back!";]]>
  215. </programlisting>
  216. </para>
  217. <para>
  218. 동일성을 위하여 다음의 형태는 허용되지 않습니다:
  219. <programlisting role="php"><![CDATA[
  220. $greeting = "Hello ${name}, welcome back!";]]>
  221. </programlisting>
  222. </para>
  223. </sect3>
  224. <sect3 id="coding-standard.coding-style.strings.string-concatenation">
  225. <title>변수의 연결</title>
  226. <para>
  227. 문자변수들은 "." 연산자를 이용하여 상호 연결됩니다. 좀더 편안한 가독을 위해 반드시 공백문자열이 "." 연산자 전후에 위치해야 합니다:
  228. <programlisting role="php"><![CDATA[
  229. $company = 'Zend' . 'Technologies';]]>
  230. </programlisting>
  231. </para>
  232. <para>
  233. "." 연산자를 이용하여 문자열을 합칠때,
  234. When concatenating strings with the "." operator, it is permitted to
  235. break the statement into multiple lines to improve readability. In these
  236. cases, each successive line should be padded with whitespace such that the
  237. "."; operator is aligned under the "=" operator:
  238. <programlisting role="php"><![CDATA[
  239. $sql = "SELECT `id`, `name` FROM `people` "
  240. . "WHERE `name` = 'Susan' "
  241. . "ORDER BY `name` ASC ";]]>
  242. </programlisting>
  243. </para>
  244. </sect3>
  245. </sect2>
  246. <sect2 id="coding-standard.coding-style.arrays">
  247. <title>어레이</title>
  248. <sect3 id="coding-standard.coding-style.arrays.numerically-indexed">
  249. <title>산술 인덱스 어레이</title>
  250. <para>음수는 인텍스로서 허용되지 않습니다.</para>
  251. <para>
  252. An indexed array may be started with any non-negative number, however
  253. this is discouraged and it is recommended that all arrays have a base index of 0.
  254. </para>
  255. <para>
  256. When declaring indexed arrays with the <code>array</code> construct, a trailing space must be
  257. added after each comma delimiter to improve readability:
  258. <programlisting role="php"><![CDATA[
  259. $sampleArray = array(1, 2, 3, 'Zend', 'Studio');]]>
  260. </programlisting>
  261. </para>
  262. <para>
  263. It is also permitted to declare multiline indexed arrays using the "array" construct.
  264. In this case, each successive line must be padded with spaces such that beginning of
  265. each line aligns as shown below:
  266. <programlisting role="php"><![CDATA[
  267. $sampleArray = array(1, 2, 3, 'Zend', 'Studio',
  268. $a, $b, $c,
  269. 56.44, $d, 500);]]>
  270. </programlisting>
  271. </para>
  272. </sect3>
  273. <sect3 id="coding-standard.coding-style.arrays.associative">
  274. <title>Associative Arrays</title>
  275. <para>
  276. When declaring associative arrays with the <code>array</code> construct, it is encouraged
  277. to break the statement into multiple lines. In this case, each successive line must be
  278. padded with whitespace such that both the keys and the values are aligned:
  279. <programlisting role="php"><![CDATA[
  280. $sampleArray = array('firstKey' => 'firstValue',
  281. 'secondKey' => 'secondValue');]]>
  282. </programlisting>
  283. </para>
  284. </sect3>
  285. </sect2>
  286. <sect2 id="coding-standard.coding-style.classes">
  287. <title>Classes</title>
  288. <sect3 id="coding-standard.coding-style.classes.declaration">
  289. <title>Class Declaration</title>
  290. <para>
  291. Classes must be named by following the naming conventions.
  292. </para><para>
  293. The brace is always written on the line underneath the class name ("one true brace" form).
  294. </para><para>
  295. Every class must have a documentation block that conforms to the PHPDocumentor standard.
  296. </para><para>
  297. Any code within a class must be indented four spaces.
  298. </para><para>
  299. Only one class is permitted per PHP file.
  300. </para><para>
  301. 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.
  302. </para><para>
  303. This is an example of an acceptable class declaration:
  304. <programlisting role="php"><![CDATA[
  305. /**
  306. * Documentation Block Here
  307. */
  308. class SampleClass
  309. {
  310. // entire content of class
  311. // must be indented four spaces
  312. }]]>
  313. </programlisting>
  314. </para>
  315. </sect3>
  316. <sect3 id="coding-standard.coding-style.classes.member-variables">
  317. <title>클라스 뱀버 변수</title>
  318. <para>
  319. Member variables must be named by following the variable naming conventions.
  320. </para><para>
  321. Any variables declared in a class must be listed at the top of the class, prior
  322. to declaring any functions.
  323. </para><para>
  324. The <code>var</code> construct is not permitted. Member variables always declare
  325. their visibility by using one of the <code>private</code>, <code>protected</code>,
  326. or <code>public</code> constructs. Accessing member variables directly by making
  327. them public is permitted but discouraged in favor of accessor
  328. variables (set/get).
  329. </para>
  330. </sect3>
  331. </sect2>
  332. <sect2 id="coding-standard.coding-style.functions-and-methods">
  333. <title>Functions and Methods</title>
  334. <sect3 id="coding-standard.coding-style.functions-and-methods.declaration">
  335. <title>Function and Method Declaration</title>
  336. <para>
  337. Functions must be named by following the naming conventions.
  338. </para><para>
  339. Functions inside classes must always declare their visibility by using
  340. one of the <code>private</code>, <code>protected</code>,
  341. or <code>public</code> constructs.
  342. </para><para>
  343. Like classes, the brace is always written on the line underneath the
  344. function name ("one true brace" form).
  345. There is no space between the
  346. function name and the opening parenthesis for the arguments.
  347. </para><para>
  348. Functions in the global scope are strongly discouraged.
  349. </para><para>
  350. This is an example of an acceptable function declaration in a class:
  351. <programlisting role="php"><![CDATA[
  352. /**
  353. * Documentation Block Here
  354. */
  355. class Foo
  356. {
  357. /**
  358. * Documentation Block Here
  359. */
  360. public function bar()
  361. {
  362. // entire content of function
  363. // must be indented four spaces
  364. }
  365. }]]>
  366. </programlisting>
  367. </para>
  368. <para>
  369. <emphasis>NOTE:</emphasis> Passing by-reference is permitted in the function declaration only:
  370. <programlisting role="php"><![CDATA[
  371. /**
  372. * Documentation Block Here
  373. */
  374. class Foo
  375. {
  376. /**
  377. * Documentation Block Here
  378. */
  379. public function bar(&$baz)
  380. {}
  381. }]]>
  382. </programlisting>
  383. </para>
  384. <para>
  385. Call-time pass by-reference 는 금지되어 있습니다.
  386. </para>
  387. <para>
  388. 반환되는 값은 괄호로 처리되여서는 안됩니다. 괄호안에 쌓인 반환값은 젠드 프레임워크의 가독력을 방해하며 반환되는 리퍼런스로 메소드가 변환될시 코드에 피해를 줄수도 있습니다.
  389. <programlisting role="php"><![CDATA[
  390. /**
  391. * Documentation Block Here
  392. */
  393. class Foo
  394. {
  395. /**
  396. * WRONG
  397. */
  398. public function bar()
  399. {
  400. return($this->bar);
  401. }
  402. /**
  403. * RIGHT
  404. */
  405. public function bar()
  406. {
  407. return $this->bar;
  408. }
  409. }]]>
  410. </programlisting>
  411. </para>
  412. </sect3>
  413. <sect3 id="coding-standard.coding-style.functions-and-methods.usage">
  414. <title>Function과 Method의 사용</title>
  415. <para>
  416. Function의 인자(arguments)들은 콤파 구분자와 하나의 공백문자로 구분되어 집니다. 다음은 세개의 인자를 가지고 있는 Function의 허용예입니다:
  417. <programlisting role="php"><![CDATA[
  418. threeArguments(1, 2, 3);]]>
  419. </programlisting>
  420. </para>
  421. <para>
  422. Call-time pass by-reference is prohibited. See the function declarations section
  423. for the proper way to pass function arguments by-reference.
  424. </para><para>
  425. For functions whose arguments permitted arrays, the function call may include the
  426. "array" construct and can be split into multiple lines to improve readability. In
  427. these cases, the standards for writing arrays still apply:
  428. <programlisting role="php"><![CDATA[
  429. threeArguments(array(1, 2, 3), 2, 3);
  430. threeArguments(array(1, 2, 3, 'Zend', 'Studio',
  431. $a, $b, $c,
  432. 56.44, $d, 500), 2, 3);]]>
  433. </programlisting>
  434. </para>
  435. </sect3>
  436. </sect2>
  437. <sect2 id="coding-standard.coding-style.control-statements">
  438. <title>Control Statements</title>
  439. <sect3 id="coding-standard.coding-style.control-statements.if-else-elseif">
  440. <title>If / Else / Elseif</title>
  441. <para>
  442. Control statements based on the <code>if</code> and <code>elseif</code>
  443. constructs must have a single space before the opening parenthesis of the conditional,
  444. and a single space after the closing parenthesis.
  445. </para>
  446. <para>
  447. Within the conditional statements between the parentheses, operators must be separated
  448. by spaces for readability. Inner parentheses are encouraged to improve logical grouping
  449. of larger conditionals.
  450. </para>
  451. <para>
  452. The opening brace is written on the same line as the conditional statement. The closing
  453. brace is always written on its own line. Any content within the braces must be
  454. indented four spaces.
  455. <programlisting role="php"><![CDATA[
  456. if ($a != 2) {
  457. $a = 2;
  458. }]]>
  459. </programlisting>
  460. </para>
  461. <para>
  462. For "if" statements that include "elseif" or "else", the formatting must be
  463. as in these examples:
  464. <programlisting role="php"><![CDATA[
  465. if ($a != 2) {
  466. $a = 2;
  467. } else {
  468. $a = 7;
  469. }
  470. if ($a != 2) {
  471. $a = 2;
  472. } elseif ($a == 3) {
  473. $a = 4;
  474. } else {
  475. $a = 7;
  476. }]]>
  477. </programlisting>
  478. PHP allows for these statements to be written without braces in some circumstances.
  479. The coding standard makes no differentiation and all "if", "elseif" or "else" statements
  480. must use braces.
  481. </para>
  482. <para>
  483. Use of the "elseif" construct is permitted but highly discouraged in favor of the
  484. "else if" combination.
  485. </para>
  486. </sect3>
  487. <sect3 id="coding-standards.coding-style.control-statements.switch">
  488. <title>Switch</title>
  489. <para>
  490. Control statements written with the "switch" construct must have a single space before
  491. the opening parenthesis of the conditional statement, and also a single space after
  492. the closing parenthesis.
  493. </para>
  494. <para>
  495. All content within the "switch" statement must be indented four spaces. Content under
  496. each "case" statement must be indented an additional four spaces.
  497. </para>
  498. <programlisting role="php"><![CDATA[
  499. switch ($numPeople) {
  500. case 1:
  501. break;
  502. case 2:
  503. break;
  504. default:
  505. break;
  506. }]]>
  507. </programlisting>
  508. <para>
  509. The construct <code>default</code> may never be omitted from a <code>switch</code> statement.
  510. </para>
  511. <para>
  512. <emphasis>NOTE:</emphasis> It is sometimes useful to write a <code>case</code> statement which falls through
  513. to the next case by not including a <code>break</code> or <code>return</code> in that case. To distinguish
  514. these cases from bugs, any <code>case</code> statement where <code>break</code> or <code>return</code> are
  515. omitted must contain the comment "// break intentionally omitted".
  516. </para>
  517. </sect3>
  518. </sect2>
  519. <sect2 id="coding-standards.inline-documentation">
  520. <title>Inline Documentation</title>
  521. <sect3 id="coding-standards.inline-documentation.documentation-format">
  522. <title>Documentation Format</title>
  523. <para>
  524. All documentation blocks ("docblocks") must be compatible with the phpDocumentor format.
  525. Describing the phpDocumentor format is beyond the scope of this document.
  526. For more information, visit: <ulink url="http://phpdoc.org/">http://phpdoc.org/</ulink>
  527. </para>
  528. <para>
  529. All source code file written for Zend Framework or that operates with the framework
  530. must contain a "file-level" docblock at the top of each file and a "class-level" docblock
  531. immediately above each class. Below are examples of such docblocks.
  532. </para>
  533. </sect3>
  534. <sect3 id="coding-standards.inline-documentation.files">
  535. <title>Files</title>
  536. <para>
  537. Every file that contains PHP code must have a header block at the top of the file that
  538. contains these phpDocumentor tags at a minimum:
  539. <programlisting role="php"><![CDATA[
  540. /**
  541. * Short description for file
  542. *
  543. * Long description for file (if any)...
  544. *
  545. * LICENSE: Some license information
  546. *
  547. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  548. * @license http://www.zend.com/license/3_0.txt PHP License 3.0
  549. * @version $Id:$
  550. * @link http://dev.zend.com/package/PackageName
  551. * @since File available since Release 1.2.0
  552. */]]>
  553. </programlisting>
  554. </para>
  555. </sect3>
  556. <sect3 id="coding-standards.inline-documentation.classes">
  557. <title>Classes</title>
  558. <para>
  559. Every class must have a docblock that contains these phpDocumentor tags at a minimum:
  560. <programlisting role="php"><![CDATA[
  561. /**
  562. * Short description for class
  563. *
  564. * Long description for class (if any)...
  565. *
  566. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  567. * @license http://www.zend.com/license/3_0.txt PHP License 3.0
  568. * @version Release: @package_version@
  569. * @link http://dev.zend.com/package/PackageName
  570. * @since Class available since Release 1.2.0
  571. * @deprecated Class deprecated in Release 2.0.0
  572. */]]>
  573. </programlisting>
  574. </para>
  575. </sect3>
  576. <sect3 id="coding-standards.inline-documentation.functions">
  577. <title>Functions</title>
  578. <para>
  579. Every function, including object methods, must have a docblock that contains at a minimum:
  580. <itemizedlist>
  581. <listitem><para>A description of the function</para></listitem>
  582. <listitem><para>All of the arguments</para></listitem>
  583. <listitem><para>All of the possible return values</para></listitem>
  584. </itemizedlist>
  585. </para>
  586. <para>
  587. It is not necessary to use the "@access" tag because the access level is already known
  588. from the "public", "private", or "protected" construct used to declare the function.
  589. </para>
  590. <para>
  591. Function이나 Method의 익셉션 throw 할경우, @thorws를 이용해야 합니다:
  592. <programlisting role="php"><![CDATA[
  593. @throws exceptionclass [description]]]>
  594. </programlisting>
  595. </para>
  596. </sect3>
  597. </sect2>
  598. </sect1>
  599. </appendix>
  600. <!--
  601. vim:se ts=4 sw=4 et:
  602. -->