blob: 84b3486a7558c359ff8f2734d71c1f253d195559 [file] [log] [blame]
Andrey Andreevc5769952019-01-16 17:49:35 +02001
2
3<!DOCTYPE html>
4<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
5<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
6<head>
7 <meta charset="utf-8">
8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
10 <title>PHP Style Guide &mdash; CodeIgniter 3.1.10 documentation</title>
11
12
13
14
15 <link rel="shortcut icon" href="../_static/ci-icon.ico"/>
16
17
18
19 <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
20
21
22
23
24
25
26
27
28
29 <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
30
31
32
33 <link rel="index" title="Index"
34 href="../genindex.html"/>
35 <link rel="search" title="Search" href="../search.html"/>
36 <link rel="top" title="CodeIgniter 3.1.10 documentation" href="../index.html"/>
37 <link rel="up" title="General Topics" href="index.html"/>
38 <link rel="next" title="Libraries" href="../libraries/index.html"/>
39 <link rel="prev" title="Security" href="security.html"/>
40
41
42 <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
43
44</head>
45
46<body class="wy-body-for-nav" role="document">
47
48 <div id="nav">
49 <div id="nav_inner">
50
51
52
53 <div id="pulldown-menu" class="ciNav">
54 <ul>
55<li class="toctree-l1"><a class="reference internal" href="welcome.html">Welcome to CodeIgniter</a></li>
56</ul>
57<ul>
58<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
59<li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
60<li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
61<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
62<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
63</ul>
64</li>
65</ul>
66<ul>
67<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
68<li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
69<li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
70<li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
71<li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
72<li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
73<li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
74</ul>
75</li>
76</ul>
77<ul>
78<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
79<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
80<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
81<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
82<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
83</ul>
84</li>
85</ul>
86<ul>
87<li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
88<li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
89<li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
90</ul>
91</li>
92</ul>
93<ul class="current">
94<li class="toctree-l1 current"><a class="reference internal" href="index.html">General Topics</a><ul class="current">
95<li class="toctree-l2"><a class="reference internal" href="urls.html">CodeIgniter URLs</a></li>
96<li class="toctree-l2"><a class="reference internal" href="controllers.html">Controllers</a></li>
97<li class="toctree-l2"><a class="reference internal" href="reserved_names.html">Reserved Names</a></li>
98<li class="toctree-l2"><a class="reference internal" href="views.html">Views</a></li>
99<li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li>
100<li class="toctree-l2"><a class="reference internal" href="helpers.html">Helpers</a></li>
101<li class="toctree-l2"><a class="reference internal" href="libraries.html">Using CodeIgniter Libraries</a></li>
102<li class="toctree-l2"><a class="reference internal" href="creating_libraries.html">Creating Libraries</a></li>
103<li class="toctree-l2"><a class="reference internal" href="drivers.html">Using CodeIgniter Drivers</a></li>
104<li class="toctree-l2"><a class="reference internal" href="creating_drivers.html">Creating Drivers</a></li>
105<li class="toctree-l2"><a class="reference internal" href="core_classes.html">Creating Core System Classes</a></li>
106<li class="toctree-l2"><a class="reference internal" href="ancillary_classes.html">Creating Ancillary Classes</a></li>
107<li class="toctree-l2"><a class="reference internal" href="hooks.html">Hooks - Extending the Framework Core</a></li>
108<li class="toctree-l2"><a class="reference internal" href="autoloader.html">Auto-loading Resources</a></li>
109<li class="toctree-l2"><a class="reference internal" href="common_functions.html">Common Functions</a></li>
110<li class="toctree-l2"><a class="reference internal" href="compatibility_functions.html">Compatibility Functions</a></li>
111<li class="toctree-l2"><a class="reference internal" href="routing.html">URI Routing</a></li>
112<li class="toctree-l2"><a class="reference internal" href="errors.html">Error Handling</a></li>
113<li class="toctree-l2"><a class="reference internal" href="caching.html">Caching</a></li>
114<li class="toctree-l2"><a class="reference internal" href="profiling.html">Profiling Your Application</a></li>
115<li class="toctree-l2"><a class="reference internal" href="cli.html">Running via the CLI</a></li>
116<li class="toctree-l2"><a class="reference internal" href="managing_apps.html">Managing your Applications</a></li>
117<li class="toctree-l2"><a class="reference internal" href="environments.html">Handling Multiple Environments</a></li>
118<li class="toctree-l2"><a class="reference internal" href="alternative_php.html">Alternate PHP Syntax for View Files</a></li>
119<li class="toctree-l2"><a class="reference internal" href="security.html">Security</a></li>
120<li class="toctree-l2 current"><a class="current reference internal" href="#">PHP Style Guide</a></li>
121</ul>
122</li>
123</ul>
124<ul>
125<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
126<li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
127<li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
128<li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
129<li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
130<li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
131<li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
132<li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
133<li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
134<li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
135<li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
136<li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
137<li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
138<li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
139<li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
140<li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
141<li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
142<li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
143<li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
144<li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
145<li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
146<li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
147<li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
148<li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
149<li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
150<li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
151<li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
152<li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
153<li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
154<li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
155<li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
156</ul>
157</li>
158</ul>
159<ul>
160<li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
161<li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
162<li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
163<li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
164<li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
165<li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
166<li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
167<li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
168<li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
169<li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
170<li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
171<li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
172<li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
173<li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
174<li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
175</ul>
176</li>
177</ul>
178<ul>
179<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
180<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
181<li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
182<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
183<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
184<li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
185<li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
186<li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
187<li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
188<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
189<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
190<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
191<li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
192<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
193<li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
194<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
195<li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
196<li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
197<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
198<li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
199<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
200<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
201</ul>
202</li>
203</ul>
204
205 </div>
206
207
208 </div>
209</div>
210<div id="nav2">
211 <a href="#" id="openToc">
212 <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" />
213 </a>
214</div>
215
216 <div class="wy-grid-for-nav">
217
218
219 <nav data-toggle="wy-nav-shift" class="wy-nav-side">
220 <div class="wy-side-nav-search">
221
222 <a href="../index.html" class="fa fa-home"> CodeIgniter</a>
223
224
225<div role="search">
226 <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
227 <input type="text" name="q" placeholder="Search docs" />
228 <input type="hidden" name="check_keywords" value="yes" />
229 <input type="hidden" name="area" value="default" />
230 </form>
231</div>
232 </div>
233
234 <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
235
236
237
238 <ul>
239<li class="toctree-l1"><a class="reference internal" href="welcome.html">Welcome to CodeIgniter</a></li>
240</ul>
241<ul>
242<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
243<li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
244<li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
245<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
246<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
247</ul>
248</li>
249</ul>
250<ul>
251<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
252<li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
253<li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
254<li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
255<li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
256<li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
257<li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
258</ul>
259</li>
260</ul>
261<ul>
262<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
263<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
264<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
265<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
266<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
267</ul>
268</li>
269</ul>
270<ul>
271<li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
272<li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
273<li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
274</ul>
275</li>
276</ul>
277<ul class="current">
278<li class="toctree-l1 current"><a class="reference internal" href="index.html">General Topics</a><ul class="current">
279<li class="toctree-l2"><a class="reference internal" href="urls.html">CodeIgniter URLs</a></li>
280<li class="toctree-l2"><a class="reference internal" href="controllers.html">Controllers</a></li>
281<li class="toctree-l2"><a class="reference internal" href="reserved_names.html">Reserved Names</a></li>
282<li class="toctree-l2"><a class="reference internal" href="views.html">Views</a></li>
283<li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li>
284<li class="toctree-l2"><a class="reference internal" href="helpers.html">Helpers</a></li>
285<li class="toctree-l2"><a class="reference internal" href="libraries.html">Using CodeIgniter Libraries</a></li>
286<li class="toctree-l2"><a class="reference internal" href="creating_libraries.html">Creating Libraries</a></li>
287<li class="toctree-l2"><a class="reference internal" href="drivers.html">Using CodeIgniter Drivers</a></li>
288<li class="toctree-l2"><a class="reference internal" href="creating_drivers.html">Creating Drivers</a></li>
289<li class="toctree-l2"><a class="reference internal" href="core_classes.html">Creating Core System Classes</a></li>
290<li class="toctree-l2"><a class="reference internal" href="ancillary_classes.html">Creating Ancillary Classes</a></li>
291<li class="toctree-l2"><a class="reference internal" href="hooks.html">Hooks - Extending the Framework Core</a></li>
292<li class="toctree-l2"><a class="reference internal" href="autoloader.html">Auto-loading Resources</a></li>
293<li class="toctree-l2"><a class="reference internal" href="common_functions.html">Common Functions</a></li>
294<li class="toctree-l2"><a class="reference internal" href="compatibility_functions.html">Compatibility Functions</a></li>
295<li class="toctree-l2"><a class="reference internal" href="routing.html">URI Routing</a></li>
296<li class="toctree-l2"><a class="reference internal" href="errors.html">Error Handling</a></li>
297<li class="toctree-l2"><a class="reference internal" href="caching.html">Caching</a></li>
298<li class="toctree-l2"><a class="reference internal" href="profiling.html">Profiling Your Application</a></li>
299<li class="toctree-l2"><a class="reference internal" href="cli.html">Running via the CLI</a></li>
300<li class="toctree-l2"><a class="reference internal" href="managing_apps.html">Managing your Applications</a></li>
301<li class="toctree-l2"><a class="reference internal" href="environments.html">Handling Multiple Environments</a></li>
302<li class="toctree-l2"><a class="reference internal" href="alternative_php.html">Alternate PHP Syntax for View Files</a></li>
303<li class="toctree-l2"><a class="reference internal" href="security.html">Security</a></li>
304<li class="toctree-l2 current"><a class="current reference internal" href="#">PHP Style Guide</a></li>
305</ul>
306</li>
307</ul>
308<ul>
309<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
310<li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
311<li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
312<li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
313<li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
314<li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
315<li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
316<li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
317<li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
318<li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
319<li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
320<li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
321<li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
322<li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
323<li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
324<li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
325<li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
326<li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
327<li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
328<li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
329<li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
330<li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
331<li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
332<li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
333<li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
334<li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
335<li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
336<li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
337<li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
338<li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
339<li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
340</ul>
341</li>
342</ul>
343<ul>
344<li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
345<li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
346<li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
347<li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
348<li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
349<li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
350<li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
351<li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
352<li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
353<li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
354<li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
355<li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
356<li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
357<li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
358<li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
359</ul>
360</li>
361</ul>
362<ul>
363<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
364<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
365<li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
366<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
367<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
368<li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
369<li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
370<li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
371<li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
372<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
373<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
374<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
375<li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
376<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
377<li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
378<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
379<li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
380<li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
381<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
382<li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
383<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
384<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
385</ul>
386</li>
387</ul>
388
389
390
391 </div>
392 &nbsp;
393 </nav>
394
395 <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
396
397
398 <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
399 <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
400 <a href="../index.html">CodeIgniter</a>
401 </nav>
402
403
404
405 <div class="wy-nav-content">
406 <div class="rst-content">
407 <div role="navigation" aria-label="breadcrumbs navigation">
408 <ul class="wy-breadcrumbs">
409 <li><a href="../index.html">Docs</a> &raquo;</li>
410
411 <li><a href="index.html">General Topics</a> &raquo;</li>
412
413 <li>PHP Style Guide</li>
414 <li class="wy-breadcrumbs-aside">
415
416 </li>
417 <div style="float:right;margin-left:5px;" id="closeMe">
418 <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
419 </div>
420 </ul>
421 <hr/>
422</div>
423 <div role="main" class="document">
424
425 <div class="section" id="php-style-guide">
426<h1><a class="toc-backref" href="#id1">PHP Style Guide</a><a class="headerlink" href="#php-style-guide" title="Permalink to this headline"></a></h1>
427<p>The following page describes the coding styles adhered to when
428contributing to the development of CodeIgniter. There is no requirement
429to use these styles in your own CodeIgniter application, though they
430are recommended.</p>
431<div class="contents topic" id="table-of-contents">
432<p class="topic-title first">Table of Contents</p>
433<ul class="simple">
434<li><a class="reference internal" href="#php-style-guide" id="id1">PHP Style Guide</a><ul>
435<li><a class="reference internal" href="#file-format" id="id2">File Format</a><ul>
436<li><a class="reference internal" href="#textmate" id="id3">TextMate</a></li>
437<li><a class="reference internal" href="#bbedit" id="id4">BBEdit</a></li>
438</ul>
439</li>
440<li><a class="reference internal" href="#php-closing-tag" id="id5">PHP Closing Tag</a></li>
441<li><a class="reference internal" href="#file-naming" id="id6">File Naming</a></li>
442<li><a class="reference internal" href="#class-and-method-naming" id="id7">Class and Method Naming</a></li>
443<li><a class="reference internal" href="#variable-names" id="id8">Variable Names</a></li>
444<li><a class="reference internal" href="#commenting" id="id9">Commenting</a></li>
445<li><a class="reference internal" href="#constants" id="id10">Constants</a></li>
446<li><a class="reference internal" href="#true-false-and-null" id="id11">TRUE, FALSE, and NULL</a></li>
447<li><a class="reference internal" href="#logical-operators" id="id12">Logical Operators</a></li>
448<li><a class="reference internal" href="#comparing-return-values-and-typecasting" id="id13">Comparing Return Values and Typecasting</a></li>
449<li><a class="reference internal" href="#debugging-code" id="id14">Debugging Code</a></li>
450<li><a class="reference internal" href="#whitespace-in-files" id="id15">Whitespace in Files</a></li>
451<li><a class="reference internal" href="#compatibility" id="id16">Compatibility</a></li>
452<li><a class="reference internal" href="#one-file-per-class" id="id17">One File per Class</a></li>
453<li><a class="reference internal" href="#whitespace" id="id18">Whitespace</a></li>
454<li><a class="reference internal" href="#line-breaks" id="id19">Line Breaks</a></li>
455<li><a class="reference internal" href="#code-indenting" id="id20">Code Indenting</a></li>
456<li><a class="reference internal" href="#bracket-and-parenthetic-spacing" id="id21">Bracket and Parenthetic Spacing</a></li>
457<li><a class="reference internal" href="#localized-text" id="id22">Localized Text</a></li>
458<li><a class="reference internal" href="#private-methods-and-variables" id="id23">Private Methods and Variables</a></li>
459<li><a class="reference internal" href="#php-errors" id="id24">PHP Errors</a></li>
460<li><a class="reference internal" href="#short-open-tags" id="id25">Short Open Tags</a></li>
461<li><a class="reference internal" href="#one-statement-per-line" id="id26">One Statement Per Line</a></li>
462<li><a class="reference internal" href="#strings" id="id27">Strings</a></li>
463<li><a class="reference internal" href="#sql-queries" id="id28">SQL Queries</a></li>
464<li><a class="reference internal" href="#default-function-arguments" id="id29">Default Function Arguments</a></li>
465</ul>
466</li>
467</ul>
468</div>
469<div class="section" id="file-format">
470<h2><a class="toc-backref" href="#id2">File Format</a><a class="headerlink" href="#file-format" title="Permalink to this headline"></a></h2>
471<p>Files should be saved with Unicode (UTF-8) encoding. The BOM should
472<em>not</em> be used. Unlike UTF-16 and UTF-32, there’s no byte order to
473indicate in a UTF-8 encoded file, and the BOM can have a negative side
474effect in PHP of sending output, preventing the application from being
475able to set its own headers. Unix line endings should be used (LF).</p>
476<p>Here is how to apply these settings in some of the more common text
477editors. Instructions for your text editor may vary; check your text
478editor’s documentation.</p>
479<div class="section" id="textmate">
480<h3><a class="toc-backref" href="#id3">TextMate</a><a class="headerlink" href="#textmate" title="Permalink to this headline"></a></h3>
481<ol class="arabic simple">
482<li>Open the Application Preferences</li>
483<li>Click Advanced, and then the “Saving” tab</li>
484<li>In “File Encoding”, select “UTF-8 (recommended)”</li>
485<li>In “Line Endings”, select “LF (recommended)”</li>
486<li><em>Optional:</em> Check “Use for existing files as well” if you wish to
487modify the line endings of files you open to your new preference.</li>
488</ol>
489</div>
490<div class="section" id="bbedit">
491<h3><a class="toc-backref" href="#id4">BBEdit</a><a class="headerlink" href="#bbedit" title="Permalink to this headline"></a></h3>
492<ol class="arabic simple">
493<li>Open the Application Preferences</li>
494<li>Select “Text Encodings” on the left.</li>
495<li>In “Default text encoding for new documents”, select “Unicode (UTF-8,
496no BOM)”</li>
497<li><em>Optional:</em> In “If file’s encoding can’t be guessed, use”, select
498“Unicode (UTF-8, no BOM)”</li>
499<li>Select “Text Files” on the left.</li>
500<li>In “Default line breaks”, select “Mac OS X and Unix (LF)”</li>
501</ol>
502</div>
503</div>
504<div class="section" id="php-closing-tag">
505<h2><a class="toc-backref" href="#id5">PHP Closing Tag</a><a class="headerlink" href="#php-closing-tag" title="Permalink to this headline"></a></h2>
506<p>The PHP closing tag on a PHP document <strong>?&gt;</strong> is optional to the PHP
507parser. However, if used, any whitespace following the closing tag,
508whether introduced by the developer, user, or an FTP application, can
509cause unwanted output, PHP errors, or if the latter are suppressed,
510blank pages. For this reason, all PHP files MUST OMIT the PHP closing
511tag and end with a single empty line instead.</p>
512</div>
513<div class="section" id="file-naming">
514<h2><a class="toc-backref" href="#id6">File Naming</a><a class="headerlink" href="#file-naming" title="Permalink to this headline"></a></h2>
515<p>Class files must be named in a Ucfirst-like manner, while any other file name
516(configurations, views, generic scripts, etc.) should be in all lowercase.</p>
517<p><strong>INCORRECT</strong>:</p>
518<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">somelibrary</span><span class="o">.</span><span class="nx">php</span>
519<span class="nx">someLibrary</span><span class="o">.</span><span class="nx">php</span>
520<span class="nx">SOMELIBRARY</span><span class="o">.</span><span class="nx">php</span>
521<span class="nx">Some_Library</span><span class="o">.</span><span class="nx">php</span>
522
523<span class="nx">Application_config</span><span class="o">.</span><span class="nx">php</span>
524<span class="nx">Application_Config</span><span class="o">.</span><span class="nx">php</span>
525<span class="nx">applicationConfig</span><span class="o">.</span><span class="nx">php</span>
526</pre></div>
527</div>
528<p><strong>CORRECT</strong>:</p>
529<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">Somelibrary</span><span class="o">.</span><span class="nx">php</span>
530<span class="nx">Some_library</span><span class="o">.</span><span class="nx">php</span>
531
532<span class="nx">applicationconfig</span><span class="o">.</span><span class="nx">php</span>
533<span class="nx">application_config</span><span class="o">.</span><span class="nx">php</span>
534</pre></div>
535</div>
536<p>Furthermore, class file names should match the name of the class itself.
537For example, if you have a class named <cite>Myclass</cite>, then its filename must
538be <strong>Myclass.php</strong>.</p>
539</div>
540<div class="section" id="class-and-method-naming">
541<h2><a class="toc-backref" href="#id7">Class and Method Naming</a><a class="headerlink" href="#class-and-method-naming" title="Permalink to this headline"></a></h2>
542<p>Class names should always start with an uppercase letter. Multiple words
543should be separated with an underscore, and not CamelCased.</p>
544<p><strong>INCORRECT</strong>:</p>
545<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">superclass</span>
546<span class="k">class</span> <span class="nc">SuperClass</span>
547</pre></div>
548</div>
549<p><strong>CORRECT</strong>:</p>
550<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Super_class</span>
551</pre></div>
552</div>
553<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Super_class</span> <span class="p">{</span>
554
555 <span class="k">public</span> <span class="k">function</span> <span class="nf">__construct</span><span class="p">()</span>
556 <span class="p">{</span>
557
558 <span class="p">}</span>
559<span class="p">}</span>
560</pre></div>
561</div>
562<p>Class methods should be entirely lowercased and named to clearly
563indicate their function, preferably including a verb. Try to avoid
564overly long and verbose names. Multiple words should be separated
565with an underscore.</p>
566<p><strong>INCORRECT</strong>:</p>
567<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">fileproperties</span><span class="p">()</span> <span class="c1">// not descriptive and needs underscore separator</span>
568<span class="k">function</span> <span class="nf">fileProperties</span><span class="p">()</span> <span class="c1">// not descriptive and uses CamelCase</span>
569<span class="k">function</span> <span class="nf">getfileproperties</span><span class="p">()</span> <span class="c1">// Better! But still missing underscore separator</span>
570<span class="k">function</span> <span class="nf">getFileProperties</span><span class="p">()</span> <span class="c1">// uses CamelCase</span>
571<span class="k">function</span> <span class="nf">get_the_file_properties_from_the_file</span><span class="p">()</span> <span class="c1">// wordy</span>
572</pre></div>
573</div>
574<p><strong>CORRECT</strong>:</p>
575<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">get_file_properties</span><span class="p">()</span> <span class="c1">// descriptive, underscore separator, and all lowercase letters</span>
576</pre></div>
577</div>
578</div>
579<div class="section" id="variable-names">
580<h2><a class="toc-backref" href="#id8">Variable Names</a><a class="headerlink" href="#variable-names" title="Permalink to this headline"></a></h2>
581<p>The guidelines for variable naming are very similar to those used for
582class methods. Variables should contain only lowercase letters,
583use underscore separators, and be reasonably named to indicate their
584purpose and contents. Very short, non-word variables should only be used
585as iterators in for() loops.</p>
586<p><strong>INCORRECT</strong>:</p>
587<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$j</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">;</span> <span class="c1">// single letter variables should only be used in for() loops</span>
588<span class="nv">$Str</span> <span class="c1">// contains uppercase letters</span>
589<span class="nv">$bufferedText</span> <span class="c1">// uses CamelCasing, and could be shortened without losing semantic meaning</span>
590<span class="nv">$groupid</span> <span class="c1">// multiple words, needs underscore separator</span>
591<span class="nv">$name_of_last_city_used</span> <span class="c1">// too long</span>
592</pre></div>
593</div>
594<p><strong>CORRECT</strong>:</p>
595<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="p">(</span><span class="nv">$j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nv">$j</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nv">$j</span><span class="o">++</span><span class="p">)</span>
596<span class="nv">$str</span>
597<span class="nv">$buffer</span>
598<span class="nv">$group_id</span>
599<span class="nv">$last_city</span>
600</pre></div>
601</div>
602</div>
603<div class="section" id="commenting">
604<h2><a class="toc-backref" href="#id9">Commenting</a><a class="headerlink" href="#commenting" title="Permalink to this headline"></a></h2>
605<p>In general, code should be commented prolifically. It not only helps
606describe the flow and intent of the code for less experienced
607programmers, but can prove invaluable when returning to your own code
608months down the line. There is not a required format for comments, but
609the following are recommended.</p>
610<p><a class="reference external" href="http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblock">DocBlock</a>
611style comments preceding class, method, and property declarations so they can be
612picked up by IDEs:</p>
613<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="sd">/**</span>
614<span class="sd"> * Super Class</span>
615<span class="sd"> *</span>
616<span class="sd"> * @package Package Name</span>
617<span class="sd"> * @subpackage Subpackage</span>
618<span class="sd"> * @category Category</span>
619<span class="sd"> * @author Author Name</span>
620<span class="sd"> * @link http://example.com</span>
621<span class="sd"> */</span>
622<span class="k">class</span> <span class="nc">Super_class</span> <span class="p">{</span>
623</pre></div>
624</div>
625<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="sd">/**</span>
626<span class="sd"> * Encodes string for use in XML</span>
627<span class="sd"> *</span>
628<span class="sd"> * @param string $str Input string</span>
629<span class="sd"> * @return string</span>
630<span class="sd"> */</span>
631<span class="k">function</span> <span class="nf">xml_encode</span><span class="p">(</span><span class="nv">$str</span><span class="p">)</span>
632</pre></div>
633</div>
634<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="sd">/**</span>
635<span class="sd"> * Data for class manipulation</span>
636<span class="sd"> *</span>
637<span class="sd"> * @var array</span>
638<span class="sd"> */</span>
639<span class="k">public</span> <span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
640</pre></div>
641</div>
642<p>Use single line comments within code, leaving a blank line between large
643comment blocks and code.</p>
644<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// break up the string by newlines</span>
645<span class="nv">$parts</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="nv">$str</span><span class="p">);</span>
646
647<span class="c1">// A longer comment that needs to give greater detail on what is</span>
648<span class="c1">// occurring and why can use multiple single-line comments. Try to</span>
649<span class="c1">// keep the width reasonable, around 70 characters is the easiest to</span>
650<span class="c1">// read. Don&#39;t hesitate to link to permanent external resources</span>
651<span class="c1">// that may provide greater detail:</span>
652<span class="c1">//</span>
653<span class="c1">// http://example.com/information_about_something/in_particular/</span>
654
655<span class="nv">$parts</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">foo</span><span class="p">(</span><span class="nv">$parts</span><span class="p">);</span>
656</pre></div>
657</div>
658</div>
659<div class="section" id="constants">
660<h2><a class="toc-backref" href="#id10">Constants</a><a class="headerlink" href="#constants" title="Permalink to this headline"></a></h2>
661<p>Constants follow the same guidelines as do variables, except constants
662should always be fully uppercase. <em>Always use CodeIgniter constants when
663appropriate, i.e. SLASH, LD, RD, PATH_CACHE, etc.</em></p>
664<p><strong>INCORRECT</strong>:</p>
665<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">myConstant</span> <span class="c1">// missing underscore separator and not fully uppercase</span>
666<span class="nx">N</span> <span class="c1">// no single-letter constants</span>
667<span class="nx">S_C_VER</span> <span class="c1">// not descriptive</span>
668<span class="nv">$str</span> <span class="o">=</span> <span class="nb">str_replace</span><span class="p">(</span><span class="s1">&#39;{foo}&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">,</span> <span class="nv">$str</span><span class="p">);</span> <span class="c1">// should use LD and RD constants</span>
669</pre></div>
670</div>
671<p><strong>CORRECT</strong>:</p>
672<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">MY_CONSTANT</span>
673<span class="nx">NEWLINE</span>
674<span class="nx">SUPER_CLASS_VERSION</span>
675<span class="nv">$str</span> <span class="o">=</span> <span class="nb">str_replace</span><span class="p">(</span><span class="nx">LD</span><span class="o">.</span><span class="s1">&#39;foo&#39;</span><span class="o">.</span><span class="nx">RD</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">,</span> <span class="nv">$str</span><span class="p">);</span>
676</pre></div>
677</div>
678</div>
679<div class="section" id="true-false-and-null">
680<h2><a class="toc-backref" href="#id11">TRUE, FALSE, and NULL</a><a class="headerlink" href="#true-false-and-null" title="Permalink to this headline"></a></h2>
681<p><strong>TRUE</strong>, <strong>FALSE</strong>, and <strong>NULL</strong> keywords should always be fully
682uppercase.</p>
683<p><strong>INCORRECT</strong>:</p>
684<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="o">==</span> <span class="k">true</span><span class="p">)</span>
685<span class="nv">$bar</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span>
686<span class="k">function</span> <span class="nf">foo</span><span class="p">(</span><span class="nv">$bar</span> <span class="o">=</span> <span class="k">null</span><span class="p">)</span>
687</pre></div>
688</div>
689<p><strong>CORRECT</strong>:</p>
690<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="o">==</span> <span class="k">TRUE</span><span class="p">)</span>
691<span class="nv">$bar</span> <span class="o">=</span> <span class="k">FALSE</span><span class="p">;</span>
692<span class="k">function</span> <span class="nf">foo</span><span class="p">(</span><span class="nv">$bar</span> <span class="o">=</span> <span class="k">NULL</span><span class="p">)</span>
693</pre></div>
694</div>
695</div>
696<div class="section" id="logical-operators">
697<h2><a class="toc-backref" href="#id12">Logical Operators</a><a class="headerlink" href="#logical-operators" title="Permalink to this headline"></a></h2>
698<p>Use of the <code class="docutils literal"><span class="pre">||</span></code> “or” comparison operator is discouraged, as its clarity
699on some output devices is low (looking like the number 11, for instance).
700<code class="docutils literal"><span class="pre">&amp;&amp;</span></code> is preferred over <code class="docutils literal"><span class="pre">AND</span></code> but either are acceptable, and a space should
701always precede and follow <code class="docutils literal"><span class="pre">!</span></code>.</p>
702<p><strong>INCORRECT</strong>:</p>
703<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="o">||</span> <span class="nv">$bar</span><span class="p">)</span>
704<span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="k">AND</span> <span class="nv">$bar</span><span class="p">)</span> <span class="c1">// okay but not recommended for common syntax highlighting applications</span>
705<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$foo</span><span class="p">)</span>
706<span class="k">if</span> <span class="p">(</span><span class="o">!</span> <span class="nb">is_array</span><span class="p">(</span><span class="nv">$foo</span><span class="p">))</span>
707</pre></div>
708</div>
709<p><strong>CORRECT</strong>:</p>
710<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="k">OR</span> <span class="nv">$bar</span><span class="p">)</span>
711<span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="o">&amp;&amp;</span> <span class="nv">$bar</span><span class="p">)</span> <span class="c1">// recommended</span>
712<span class="k">if</span> <span class="p">(</span> <span class="o">!</span> <span class="nv">$foo</span><span class="p">)</span>
713<span class="k">if</span> <span class="p">(</span> <span class="o">!</span> <span class="nb">is_array</span><span class="p">(</span><span class="nv">$foo</span><span class="p">))</span>
714</pre></div>
715</div>
716</div>
717<div class="section" id="comparing-return-values-and-typecasting">
718<h2><a class="toc-backref" href="#id13">Comparing Return Values and Typecasting</a><a class="headerlink" href="#comparing-return-values-and-typecasting" title="Permalink to this headline"></a></h2>
719<p>Some PHP functions return FALSE on failure, but may also have a valid
720return value of “” or 0, which would evaluate to FALSE in loose
721comparisons. Be explicit by comparing the variable type when using these
722return values in conditionals to ensure the return value is indeed what
723you expect, and not a value that has an equivalent loose-type
724evaluation.</p>
725<p>Use the same stringency in returning and checking your own variables.
726Use <strong>===</strong> and <strong>!==</strong> as necessary.</p>
727<p><strong>INCORRECT</strong>:</p>
728<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// If &#39;foo&#39; is at the beginning of the string, strpos will return a 0,</span>
729<span class="c1">// resulting in this conditional evaluating as TRUE</span>
730<span class="k">if</span> <span class="p">(</span><span class="nb">strpos</span><span class="p">(</span><span class="nv">$str</span><span class="p">,</span> <span class="s1">&#39;foo&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="k">FALSE</span><span class="p">)</span>
731</pre></div>
732</div>
733<p><strong>CORRECT</strong>:</p>
734<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nb">strpos</span><span class="p">(</span><span class="nv">$str</span><span class="p">,</span> <span class="s1">&#39;foo&#39;</span><span class="p">)</span> <span class="o">===</span> <span class="k">FALSE</span><span class="p">)</span>
735</pre></div>
736</div>
737<p><strong>INCORRECT</strong>:</p>
738<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">build_string</span><span class="p">(</span><span class="nv">$str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
739<span class="p">{</span>
740 <span class="k">if</span> <span class="p">(</span><span class="nv">$str</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="c1">// uh-oh! What if FALSE or the integer 0 is passed as an argument?</span>
741 <span class="p">{</span>
742
743 <span class="p">}</span>
744<span class="p">}</span>
745</pre></div>
746</div>
747<p><strong>CORRECT</strong>:</p>
748<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">build_string</span><span class="p">(</span><span class="nv">$str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
749<span class="p">{</span>
750 <span class="k">if</span> <span class="p">(</span><span class="nv">$str</span> <span class="o">===</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
751 <span class="p">{</span>
752
753 <span class="p">}</span>
754<span class="p">}</span>
755</pre></div>
756</div>
757<p>See also information regarding <a class="reference external" href="http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting">typecasting</a>,
758which can be quite useful. Typecasting has a slightly different effect
759which may be desirable. When casting a variable as a string, for
760instance, NULL and boolean FALSE variables become empty strings, 0 (and
761other numbers) become strings of digits, and boolean TRUE becomes “1”:</p>
762<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$str</span> <span class="o">=</span> <span class="p">(</span><span class="nx">string</span><span class="p">)</span> <span class="nv">$str</span><span class="p">;</span> <span class="c1">// cast $str as a string</span>
763</pre></div>
764</div>
765</div>
766<div class="section" id="debugging-code">
767<h2><a class="toc-backref" href="#id14">Debugging Code</a><a class="headerlink" href="#debugging-code" title="Permalink to this headline"></a></h2>
768<p>Do not leave debugging code in your submissions, even when commented out.
769Things such as <code class="docutils literal"><span class="pre">var_dump()</span></code>, <code class="docutils literal"><span class="pre">print_r()</span></code>, <code class="docutils literal"><span class="pre">die()</span></code>/<code class="docutils literal"><span class="pre">exit()</span></code> should not be included
770in your code unless it serves a specific purpose other than debugging.</p>
771</div>
772<div class="section" id="whitespace-in-files">
773<h2><a class="toc-backref" href="#id15">Whitespace in Files</a><a class="headerlink" href="#whitespace-in-files" title="Permalink to this headline"></a></h2>
774<p>No whitespace can precede the opening PHP tag or follow the closing PHP
775tag. Output is buffered, so whitespace in your files can cause output to
776begin before CodeIgniter outputs its content, leading to errors and an
777inability for CodeIgniter to send proper headers.</p>
778</div>
779<div class="section" id="compatibility">
780<h2><a class="toc-backref" href="#id16">Compatibility</a><a class="headerlink" href="#compatibility" title="Permalink to this headline"></a></h2>
781<p>CodeIgniter recommends PHP 5.6 or newer to be used, but it should be
782compatible with PHP 5.3.7. Your code must either be compatible with this
783requirement, provide a suitable fallback, or be an optional feature that
784dies quietly without affecting a user’s application.</p>
785<p>Additionally, do not use PHP functions that require non-default libraries
786to be installed unless your code contains an alternative method when the
787function is not available.</p>
788</div>
789<div class="section" id="one-file-per-class">
790<h2><a class="toc-backref" href="#id17">One File per Class</a><a class="headerlink" href="#one-file-per-class" title="Permalink to this headline"></a></h2>
791<p>Use separate files for each class, unless the classes are <em>closely related</em>.
792An example of a CodeIgniter file that contains multiple classes is the
793Xmlrpc library file.</p>
794</div>
795<div class="section" id="whitespace">
796<h2><a class="toc-backref" href="#id18">Whitespace</a><a class="headerlink" href="#whitespace" title="Permalink to this headline"></a></h2>
797<p>Use tabs for whitespace in your code, not spaces. This may seem like a
798small thing, but using tabs instead of whitespace allows the developer
799looking at your code to have indentation at levels that they prefer and
800customize in whatever application they use. And as a side benefit, it
801results in (slightly) more compact files, storing one tab character
802versus, say, four space characters.</p>
803</div>
804<div class="section" id="line-breaks">
805<h2><a class="toc-backref" href="#id19">Line Breaks</a><a class="headerlink" href="#line-breaks" title="Permalink to this headline"></a></h2>
806<p>Files must be saved with Unix line breaks. This is more of an issue for
807developers who work in Windows, but in any case ensure that your text
808editor is setup to save files with Unix line breaks.</p>
809</div>
810<div class="section" id="code-indenting">
811<h2><a class="toc-backref" href="#id20">Code Indenting</a><a class="headerlink" href="#code-indenting" title="Permalink to this headline"></a></h2>
812<p>Use Allman style indenting. With the exception of Class declarations,
813braces are always placed on a line by themselves, and indented at the
814same level as the control statement that “owns” them.</p>
815<p><strong>INCORRECT</strong>:</p>
816<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">foo</span><span class="p">(</span><span class="nv">$bar</span><span class="p">)</span> <span class="p">{</span>
817 <span class="c1">// ...</span>
818<span class="p">}</span>
819
820<span class="k">foreach</span> <span class="p">(</span><span class="nv">$arr</span> <span class="k">as</span> <span class="nv">$key</span> <span class="o">=&gt;</span> <span class="nv">$val</span><span class="p">)</span> <span class="p">{</span>
821 <span class="c1">// ...</span>
822<span class="p">}</span>
823
824<span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="o">==</span> <span class="nv">$bar</span><span class="p">)</span> <span class="p">{</span>
825 <span class="c1">// ...</span>
826<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
827 <span class="c1">// ...</span>
828<span class="p">}</span>
829
830<span class="k">for</span> <span class="p">(</span><span class="nv">$i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nv">$i</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nv">$i</span><span class="o">++</span><span class="p">)</span>
831 <span class="p">{</span>
832 <span class="k">for</span> <span class="p">(</span><span class="nv">$j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nv">$j</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nv">$j</span><span class="o">++</span><span class="p">)</span>
833 <span class="p">{</span>
834 <span class="c1">// ...</span>
835 <span class="p">}</span>
836 <span class="p">}</span>
837
838<span class="k">try</span> <span class="p">{</span>
839 <span class="c1">// ...</span>
840<span class="p">}</span>
841<span class="k">catch</span><span class="p">()</span> <span class="p">{</span>
842 <span class="c1">// ...</span>
843<span class="p">}</span>
844</pre></div>
845</div>
846<p><strong>CORRECT</strong>:</p>
847<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">foo</span><span class="p">(</span><span class="nv">$bar</span><span class="p">)</span>
848<span class="p">{</span>
849 <span class="c1">// ...</span>
850<span class="p">}</span>
851
852<span class="k">foreach</span> <span class="p">(</span><span class="nv">$arr</span> <span class="k">as</span> <span class="nv">$key</span> <span class="o">=&gt;</span> <span class="nv">$val</span><span class="p">)</span>
853<span class="p">{</span>
854 <span class="c1">// ...</span>
855<span class="p">}</span>
856
857<span class="k">if</span> <span class="p">(</span><span class="nv">$foo</span> <span class="o">==</span> <span class="nv">$bar</span><span class="p">)</span>
858<span class="p">{</span>
859 <span class="c1">// ...</span>
860<span class="p">}</span>
861<span class="k">else</span>
862<span class="p">{</span>
863 <span class="c1">// ...</span>
864<span class="p">}</span>
865
866<span class="k">for</span> <span class="p">(</span><span class="nv">$i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nv">$i</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nv">$i</span><span class="o">++</span><span class="p">)</span>
867<span class="p">{</span>
868 <span class="k">for</span> <span class="p">(</span><span class="nv">$j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nv">$j</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nv">$j</span><span class="o">++</span><span class="p">)</span>
869 <span class="p">{</span>
870 <span class="c1">// ...</span>
871 <span class="p">}</span>
872<span class="p">}</span>
873
874<span class="k">try</span>
875<span class="p">{</span>
876 <span class="c1">// ...</span>
877<span class="p">}</span>
878<span class="k">catch</span><span class="p">()</span>
879<span class="p">{</span>
880 <span class="c1">// ...</span>
881<span class="p">}</span>
882</pre></div>
883</div>
884</div>
885<div class="section" id="bracket-and-parenthetic-spacing">
886<h2><a class="toc-backref" href="#id21">Bracket and Parenthetic Spacing</a><a class="headerlink" href="#bracket-and-parenthetic-spacing" title="Permalink to this headline"></a></h2>
887<p>In general, parenthesis and brackets should not use any additional
888spaces. The exception is that a space should always follow PHP control
889structures that accept arguments with parenthesis (declare, do-while,
890elseif, for, foreach, if, switch, while), to help distinguish them from
891functions and increase readability.</p>
892<p><strong>INCORRECT</strong>:</p>
893<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$arr</span><span class="p">[</span> <span class="nv">$foo</span> <span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">;</span>
894</pre></div>
895</div>
896<p><strong>CORRECT</strong>:</p>
897<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$arr</span><span class="p">[</span><span class="nv">$foo</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">;</span> <span class="c1">// no spaces around array keys</span>
898</pre></div>
899</div>
900<p><strong>INCORRECT</strong>:</p>
901<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">foo</span> <span class="p">(</span> <span class="nv">$bar</span> <span class="p">)</span>
902<span class="p">{</span>
903
904<span class="p">}</span>
905</pre></div>
906</div>
907<p><strong>CORRECT</strong>:</p>
908<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">foo</span><span class="p">(</span><span class="nv">$bar</span><span class="p">)</span> <span class="c1">// no spaces around parenthesis in function declarations</span>
909<span class="p">{</span>
910
911<span class="p">}</span>
912</pre></div>
913</div>
914<p><strong>INCORRECT</strong>:</p>
915<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">foreach</span><span class="p">(</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">result</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$row</span> <span class="p">)</span>
916</pre></div>
917</div>
918<p><strong>CORRECT</strong>:</p>
919<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">foreach</span> <span class="p">(</span><span class="nv">$query</span><span class="o">-&gt;</span><span class="na">result</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$row</span><span class="p">)</span> <span class="c1">// single space following PHP control structures, but not in interior parenthesis</span>
920</pre></div>
921</div>
922</div>
923<div class="section" id="localized-text">
924<h2><a class="toc-backref" href="#id22">Localized Text</a><a class="headerlink" href="#localized-text" title="Permalink to this headline"></a></h2>
925<p>CodeIgniter libraries should take advantage of corresponding language files
926whenever possible.</p>
927<p><strong>INCORRECT</strong>:</p>
928<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">return</span> <span class="s2">&quot;Invalid Selection&quot;</span><span class="p">;</span>
929</pre></div>
930</div>
931<p><strong>CORRECT</strong>:</p>
932<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">return</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">lang</span><span class="o">-&gt;</span><span class="na">line</span><span class="p">(</span><span class="s1">&#39;invalid_selection&#39;</span><span class="p">);</span>
933</pre></div>
934</div>
935</div>
936<div class="section" id="private-methods-and-variables">
937<h2><a class="toc-backref" href="#id23">Private Methods and Variables</a><a class="headerlink" href="#private-methods-and-variables" title="Permalink to this headline"></a></h2>
938<p>Methods and variables that are only accessed internally,
939such as utility and helper functions that your public methods use for
940code abstraction, should be prefixed with an underscore.</p>
941<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">function</span> <span class="nf">convert_text</span><span class="p">()</span>
942<span class="k">private</span> <span class="k">function</span> <span class="nf">_convert_text</span><span class="p">()</span>
943</pre></div>
944</div>
945</div>
946<div class="section" id="php-errors">
947<h2><a class="toc-backref" href="#id24">PHP Errors</a><a class="headerlink" href="#php-errors" title="Permalink to this headline"></a></h2>
948<p>Code must run error free and not rely on warnings and notices to be
949hidden to meet this requirement. For instance, never access a variable
950that you did not set yourself (such as <code class="docutils literal"><span class="pre">$_POST</span></code> array keys) without first
951checking to see that it <code class="docutils literal"><span class="pre">isset()</span></code>.</p>
952<p>Make sure that your dev environment has error reporting enabled
953for ALL users, and that display_errors is enabled in the PHP
954environment. You can check this setting with:</p>
955<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nb">ini_get</span><span class="p">(</span><span class="s1">&#39;display_errors&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
956<span class="p">{</span>
957 <span class="k">exit</span> <span class="s2">&quot;Enabled&quot;</span><span class="p">;</span>
958<span class="p">}</span>
959</pre></div>
960</div>
961<p>On some servers where <em>display_errors</em> is disabled, and you do not have
962the ability to change this in the php.ini, you can often enable it with:</p>
963<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nb">ini_set</span><span class="p">(</span><span class="s1">&#39;display_errors&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
964</pre></div>
965</div>
966<div class="admonition note">
967<p class="first admonition-title">Note</p>
968<p class="last">Setting the <a class="reference external" href="http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors">display_errors</a>
969setting with <code class="docutils literal"><span class="pre">ini_set()</span></code> at runtime is not identical to having
970it enabled in the PHP environment. Namely, it will not have any
971effect if the script has fatal errors.</p>
972</div>
973</div>
974<div class="section" id="short-open-tags">
975<h2><a class="toc-backref" href="#id25">Short Open Tags</a><a class="headerlink" href="#short-open-tags" title="Permalink to this headline"></a></h2>
976<p>Always use full PHP opening tags, in case a server does not have
977<em>short_open_tag</em> enabled.</p>
978<p><strong>INCORRECT</strong>:</p>
979<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o">&lt;?</span> <span class="k">echo</span> <span class="nv">$foo</span><span class="p">;</span> <span class="cp">?&gt;</span>
980
981<span class="cp">&lt;?</span><span class="o">=</span><span class="nv">$foo</span><span class="cp">?&gt;</span>
982</pre></div>
983</div>
984<p><strong>CORRECT</strong>:</p>
985<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o">&lt;?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nv">$foo</span><span class="p">;</span> <span class="cp">?&gt;</span>
986</pre></div>
987</div>
988<div class="admonition note">
989<p class="first admonition-title">Note</p>
990<p class="last">PHP 5.4 will always have the <strong>&lt;?=</strong> tag available.</p>
991</div>
992</div>
993<div class="section" id="one-statement-per-line">
994<h2><a class="toc-backref" href="#id26">One Statement Per Line</a><a class="headerlink" href="#one-statement-per-line" title="Permalink to this headline"></a></h2>
995<p>Never combine statements on one line.</p>
996<p><strong>INCORRECT</strong>:</p>
997<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$foo</span> <span class="o">=</span> <span class="s1">&#39;this&#39;</span><span class="p">;</span> <span class="nv">$bar</span> <span class="o">=</span> <span class="s1">&#39;that&#39;</span><span class="p">;</span> <span class="nv">$bat</span> <span class="o">=</span> <span class="nb">str_replace</span><span class="p">(</span><span class="nv">$foo</span><span class="p">,</span> <span class="nv">$bar</span><span class="p">,</span> <span class="nv">$bag</span><span class="p">);</span>
998</pre></div>
999</div>
1000<p><strong>CORRECT</strong>:</p>
1001<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$foo</span> <span class="o">=</span> <span class="s1">&#39;this&#39;</span><span class="p">;</span>
1002<span class="nv">$bar</span> <span class="o">=</span> <span class="s1">&#39;that&#39;</span><span class="p">;</span>
1003<span class="nv">$bat</span> <span class="o">=</span> <span class="nb">str_replace</span><span class="p">(</span><span class="nv">$foo</span><span class="p">,</span> <span class="nv">$bar</span><span class="p">,</span> <span class="nv">$bag</span><span class="p">);</span>
1004</pre></div>
1005</div>
1006</div>
1007<div class="section" id="strings">
1008<h2><a class="toc-backref" href="#id27">Strings</a><a class="headerlink" href="#strings" title="Permalink to this headline"></a></h2>
1009<p>Always use single quoted strings unless you need variables parsed, and
1010in cases where you do need variables parsed, use braces to prevent
1011greedy token parsing. You may also use double-quoted strings if the
1012string contains single quotes, so you do not have to use escape
1013characters.</p>
1014<p><strong>INCORRECT</strong>:</p>
1015<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="s2">&quot;My String&quot;</span> <span class="c1">// no variable parsing, so no use for double quotes</span>
1016<span class="s2">&quot;My string </span><span class="si">$foo</span><span class="s2">&quot;</span> <span class="c1">// needs braces</span>
1017<span class="s1">&#39;SELECT foo FROM bar WHERE baz = \&#39;bag\&#39;&#39;</span> <span class="c1">// ugly</span>
1018</pre></div>
1019</div>
1020<p><strong>CORRECT</strong>:</p>
1021<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="s1">&#39;My String&#39;</span>
1022<span class="s2">&quot;My string </span><span class="si">{</span><span class="nv">$foo</span><span class="si">}</span><span class="s2">&quot;</span>
1023<span class="s2">&quot;SELECT foo FROM bar WHERE baz = &#39;bag&#39;&quot;</span>
1024</pre></div>
1025</div>
1026</div>
1027<div class="section" id="sql-queries">
1028<h2><a class="toc-backref" href="#id28">SQL Queries</a><a class="headerlink" href="#sql-queries" title="Permalink to this headline"></a></h2>
1029<p>SQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE,
1030AS, JOIN, ON, IN, etc.</p>
1031<p>Break up long queries into multiple lines for legibility, preferably
1032breaking for each clause.</p>
1033<p><strong>INCORRECT</strong>:</p>
1034<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// keywords are lowercase and query is too long for</span>
1035<span class="c1">// a single line (... indicates continuation of line)</span>
1036<span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;select foo, bar, baz, foofoo, foobar as raboof, foobaz from exp_pre_email_addresses</span>
1037<span class="s2">...where foo != &#39;oof&#39; and baz != &#39;zab&#39; order by foobaz limit 5, 100&quot;</span><span class="p">);</span>
1038</pre></div>
1039</div>
1040<p><strong>CORRECT</strong>:</p>
1041<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;SELECT foo, bar, baz, foofoo, foobar AS raboof, foobaz</span>
1042<span class="s2"> FROM exp_pre_email_addresses</span>
1043<span class="s2"> WHERE foo != &#39;oof&#39;</span>
1044<span class="s2"> AND baz != &#39;zab&#39;</span>
1045<span class="s2"> ORDER BY foobaz</span>
1046<span class="s2"> LIMIT 5, 100&quot;</span><span class="p">);</span>
1047</pre></div>
1048</div>
1049</div>
1050<div class="section" id="default-function-arguments">
1051<h2><a class="toc-backref" href="#id29">Default Function Arguments</a><a class="headerlink" href="#default-function-arguments" title="Permalink to this headline"></a></h2>
1052<p>Whenever appropriate, provide function argument defaults, which helps
1053prevent PHP errors with mistaken calls and provides common fallback
1054values which can save a few lines of code. Example:</p>
1055<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">function</span> <span class="nf">foo</span><span class="p">(</span><span class="nv">$bar</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="nv">$baz</span> <span class="o">=</span> <span class="k">FALSE</span><span class="p">)</span>
1056</pre></div>
1057</div>
1058</div>
1059</div>
1060
1061
1062 </div>
1063 <footer>
1064
1065 <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
1066
1067 <a href="../libraries/index.html" class="btn btn-neutral float-right" title="Libraries">Next <span class="fa fa-arrow-circle-right"></span></a>
1068
1069
1070 <a href="security.html" class="btn btn-neutral" title="Security"><span class="fa fa-arrow-circle-left"></span> Previous</a>
1071
1072 </div>
1073
1074
1075 <hr/>
1076
1077 <div role="contentinfo">
1078 <p>
1079 &copy; Copyright 2014 - 2019, British Columbia Institute of Technology.
1080 Last updated on Jan 16, 2019.
1081 </p>
1082 </div>
1083
1084 Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
1085
1086</footer>
1087 </div>
1088 </div>
1089
1090 </section>
1091
1092 </div>
1093
1094
1095
1096
1097
1098 <script type="text/javascript">
1099 var DOCUMENTATION_OPTIONS = {
1100 URL_ROOT:'../',
1101 VERSION:'3.1.10',
1102 COLLAPSE_INDEX:false,
1103 FILE_SUFFIX:'.html',
1104 HAS_SOURCE: false
1105 };
1106 </script>
1107 <script type="text/javascript" src="../_static/jquery.js"></script>
1108 <script type="text/javascript" src="../_static/underscore.js"></script>
1109 <script type="text/javascript" src="../_static/doctools.js"></script>
1110
1111
1112
1113
1114
1115 <script type="text/javascript" src="../_static/js/theme.js"></script>
1116
1117
1118
1119
1120 <script type="text/javascript">
1121 jQuery(function () {
1122 SphinxRtdTheme.StickyNav.enable();
1123 });
1124 </script>
1125
1126
1127</body>
1128</html>