blob: 7704a59c5bd4e60152c18f7775337901db61cb48 [file] [log] [blame]
Derek Jones619b1222011-10-10 16:26:27 -05001###############
2PHP Style Guide
3###############
4
Derek Jones8ede1a22011-10-05 13:34:52 -05005
Eric Roberts4addd5e2013-02-25 14:14:05 -06006The following page describes the coding styles adhered to when
7contributing to the development of CodeIgniter. There is no requirement
8to use these styles in your own CodeIgniter application, though they
9are recommended.
Derek Jones8ede1a22011-10-05 13:34:52 -050010
11.. contents:: Table of Contents
12
13File Format
14===========
15
16Files should be saved with Unicode (UTF-8) encoding. The BOM should
17*not* be used. Unlike UTF-16 and UTF-32, there's no byte order to
18indicate in a UTF-8 encoded file, and the BOM can have a negative side
19effect in PHP of sending output, preventing the application from being
20able to set its own headers. Unix line endings should be used (LF).
21
22Here is how to apply these settings in some of the more common text
23editors. Instructions for your text editor may vary; check your text
24editor's documentation.
25
26TextMate
27''''''''
28
29#. Open the Application Preferences
30#. Click Advanced, and then the "Saving" tab
31#. In "File Encoding", select "UTF-8 (recommended)"
32#. In "Line Endings", select "LF (recommended)"
33#. *Optional:* Check "Use for existing files as well" if you wish to
34 modify the line endings of files you open to your new preference.
35
36BBEdit
37''''''
38
39#. Open the Application Preferences
40#. Select "Text Encodings" on the left.
41#. In "Default text encoding for new documents", select "Unicode (UTF-8,
42 no BOM)"
43#. *Optional:* In "If file's encoding can't be guessed, use", select
44 "Unicode (UTF-8, no BOM)"
45#. Select "Text Files" on the left.
46#. In "Default line breaks", select "Mac OS X and Unix (LF)"
47
48PHP Closing Tag
49===============
50
51The PHP closing tag on a PHP document **?>** is optional to the PHP
52parser. However, if used, any whitespace following the closing tag,
53whether introduced by the developer, user, or an FTP application, can
54cause unwanted output, PHP errors, or if the latter are suppressed,
vlakoff93d98b62015-01-21 22:56:51 +010055blank pages. For this reason, all PHP files MUST OMIT the PHP closing
56tag and end with a single empty line instead.
Eric Roberts4addd5e2013-02-25 14:14:05 -060057
Andrey Andreev20292312013-07-22 14:29:10 +030058File Naming
59===========
60
61Class files must be named in a Ucfirst-like manner, while any other file name
62(configurations, views, generic scripts, etc.) should be in all lowercase.
63
64**INCORRECT**::
65
66 somelibrary.php
67 someLibrary.php
68 SOMELIBRARY.php
69 Some_Library.php
70
71 Application_config.php
72 Application_Config.php
73 applicationConfig.php
74
75**CORRECT**::
76
Andrey Andreeve3e2c692013-07-22 16:25:44 +030077 Somelibrary.php
78 Some_library.php
Andrey Andreev20292312013-07-22 14:29:10 +030079
80 applicationconfig.php
81 application_config.php
82
83Furthermore, class file names should match the name of the class itself.
84For example, if you have a class named `Myclass`, then its filename must
85be **Myclass.php**.
86
Derek Jones8ede1a22011-10-05 13:34:52 -050087Class and Method Naming
88=======================
89
90Class names should always start with an uppercase letter. Multiple words
Eric Roberts4addd5e2013-02-25 14:14:05 -060091should be separated with an underscore, and not CamelCased.
Derek Jones8ede1a22011-10-05 13:34:52 -050092
Derek Jones129c1812011-10-05 17:15:44 -050093**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -050094
Derek Jones129c1812011-10-05 17:15:44 -050095 class superclass
96 class SuperClass
97
98**CORRECT**::
99
100 class Super_class
Derek Jones8ede1a22011-10-05 13:34:52 -0500101
102::
103
Derek Jones129c1812011-10-05 17:15:44 -0500104 class Super_class {
Derek Jones8ede1a22011-10-05 13:34:52 -0500105
Andrey Andreevd8e1ac72012-03-26 22:22:37 +0300106 public function __construct()
Derek Jones129c1812011-10-05 17:15:44 -0500107 {
Derek Jones8ede1a22011-10-05 13:34:52 -0500108
Derek Jones129c1812011-10-05 17:15:44 -0500109 }
110 }
111
Eric Roberts4addd5e2013-02-25 14:14:05 -0600112Class methods should be entirely lowercased and named to clearly
113indicate their function, preferably including a verb. Try to avoid
Eric Robertsd746f262013-02-25 19:55:49 -0600114overly long and verbose names. Multiple words should be separated
115with an underscore.
Derek Jones129c1812011-10-05 17:15:44 -0500116
117**INCORRECT**::
118
119 function fileproperties() // not descriptive and needs underscore separator
120 function fileProperties() // not descriptive and uses CamelCase
121 function getfileproperties() // Better! But still missing underscore separator
122 function getFileProperties() // uses CamelCase
123 function get_the_file_properties_from_the_file() // wordy
124
125**CORRECT**::
126
127 function get_file_properties() // descriptive, underscore separator, and all lowercase letters
Derek Jones8ede1a22011-10-05 13:34:52 -0500128
129Variable Names
130==============
131
Eric Roberts4addd5e2013-02-25 14:14:05 -0600132The guidelines for variable naming are very similar to those used for
133class methods. Variables should contain only lowercase letters,
Derek Jones8ede1a22011-10-05 13:34:52 -0500134use underscore separators, and be reasonably named to indicate their
135purpose and contents. Very short, non-word variables should only be used
136as iterators in for() loops.
137
Derek Jones129c1812011-10-05 17:15:44 -0500138**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500139
Derek Jones129c1812011-10-05 17:15:44 -0500140 $j = 'foo'; // single letter variables should only be used in for() loops
141 $Str // contains uppercase letters
142 $bufferedText // uses CamelCasing, and could be shortened without losing semantic meaning
143 $groupid // multiple words, needs underscore separator
144 $name_of_last_city_used // too long
145
146**CORRECT**::
147
148 for ($j = 0; $j < 10; $j++)
149 $str
150 $buffer
151 $group_id
152 $last_city
Derek Jones8ede1a22011-10-05 13:34:52 -0500153
154Commenting
155==========
156
157In general, code should be commented prolifically. It not only helps
158describe the flow and intent of the code for less experienced
159programmers, but can prove invaluable when returning to your own code
160months down the line. There is not a required format for comments, but
161the following are recommended.
162
163`DocBlock <http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblock>`_
Timothy Warrenbb8ae012012-04-20 10:31:51 -0400164style comments preceding class, method, and property declarations so they can be
Derek Jones8ede1a22011-10-05 13:34:52 -0500165picked up by IDEs::
166
Derek Jones129c1812011-10-05 17:15:44 -0500167 /**
168 * Super Class
169 *
170 * @package Package Name
171 * @subpackage Subpackage
172 * @category Category
173 * @author Author Name
174 * @link http://example.com
175 */
176 class Super_class {
Derek Jones8ede1a22011-10-05 13:34:52 -0500177
178::
179
Derek Jones129c1812011-10-05 17:15:44 -0500180 /**
181 * Encodes string for use in XML
182 *
Andrey Andreev16a704c2012-11-09 17:25:00 +0200183 * @param string $str Input string
Derek Jones129c1812011-10-05 17:15:44 -0500184 * @return string
185 */
186 function xml_encode($str)
Andrey Andreev16a704c2012-11-09 17:25:00 +0200187
Timothy Warrenbb8ae012012-04-20 10:31:51 -0400188::
189
190 /**
191 * Data for class manipulation
192 *
193 * @var array
194 */
Andrey Andreev16a704c2012-11-09 17:25:00 +0200195 public $data = array();
Derek Jones8ede1a22011-10-05 13:34:52 -0500196
197Use single line comments within code, leaving a blank line between large
198comment blocks and code.
199
200::
201
Derek Jones129c1812011-10-05 17:15:44 -0500202 // break up the string by newlines
203 $parts = explode("\n", $str);
204
205 // A longer comment that needs to give greater detail on what is
206 // occurring and why can use multiple single-line comments. Try to
207 // keep the width reasonable, around 70 characters is the easiest to
208 // read. Don't hesitate to link to permanent external resources
209 // that may provide greater detail:
210 //
211 // http://example.com/information_about_something/in_particular/
212
213 $parts = $this->foo($parts);
Derek Jones8ede1a22011-10-05 13:34:52 -0500214
215Constants
216=========
217
218Constants follow the same guidelines as do variables, except constants
219should always be fully uppercase. *Always use CodeIgniter constants when
220appropriate, i.e. SLASH, LD, RD, PATH_CACHE, etc.*
221
Derek Jones129c1812011-10-05 17:15:44 -0500222**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500223
Derek Jones129c1812011-10-05 17:15:44 -0500224 myConstant // missing underscore separator and not fully uppercase
225 N // no single-letter constants
226 S_C_VER // not descriptive
227 $str = str_replace('{foo}', 'bar', $str); // should use LD and RD constants
228
229**CORRECT**::
230
231 MY_CONSTANT
232 NEWLINE
233 SUPER_CLASS_VERSION
234 $str = str_replace(LD.'foo'.RD, 'bar', $str);
Derek Jones8ede1a22011-10-05 13:34:52 -0500235
236TRUE, FALSE, and NULL
237=====================
238
239**TRUE**, **FALSE**, and **NULL** keywords should always be fully
240uppercase.
241
Derek Jones129c1812011-10-05 17:15:44 -0500242**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500243
Derek Jones129c1812011-10-05 17:15:44 -0500244 if ($foo == true)
245 $bar = false;
246 function foo($bar = null)
247
248**CORRECT**::
249
250 if ($foo == TRUE)
251 $bar = FALSE;
252 function foo($bar = NULL)
Derek Jones8ede1a22011-10-05 13:34:52 -0500253
254Logical Operators
255=================
256
Eric Robertsd746f262013-02-25 19:55:49 -0600257Use of the ``||`` "or" comparison operator is discouraged, as its clarity
Eric Roberts4addd5e2013-02-25 14:14:05 -0600258on some output devices is low (looking like the number 11, for instance).
Eric Robertsd746f262013-02-25 19:55:49 -0600259``&&`` is preferred over ``AND`` but either are acceptable, and a space should
260always precede and follow ``!``.
Derek Jones8ede1a22011-10-05 13:34:52 -0500261
Derek Jones129c1812011-10-05 17:15:44 -0500262**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500263
Derek Jones129c1812011-10-05 17:15:44 -0500264 if ($foo || $bar)
265 if ($foo AND $bar) // okay but not recommended for common syntax highlighting applications
266 if (!$foo)
267 if (! is_array($foo))
268
269**CORRECT**::
270
271 if ($foo OR $bar)
272 if ($foo && $bar) // recommended
273 if ( ! $foo)
274 if ( ! is_array($foo))
275
Derek Jones8ede1a22011-10-05 13:34:52 -0500276
277Comparing Return Values and Typecasting
278=======================================
279
280Some PHP functions return FALSE on failure, but may also have a valid
281return value of "" or 0, which would evaluate to FALSE in loose
282comparisons. Be explicit by comparing the variable type when using these
283return values in conditionals to ensure the return value is indeed what
284you expect, and not a value that has an equivalent loose-type
285evaluation.
286
287Use the same stringency in returning and checking your own variables.
288Use **===** and **!==** as necessary.
Derek Jones8ede1a22011-10-05 13:34:52 -0500289
Derek Jones129c1812011-10-05 17:15:44 -0500290**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500291
Derek Jones129c1812011-10-05 17:15:44 -0500292 // If 'foo' is at the beginning of the string, strpos will return a 0,
293 // resulting in this conditional evaluating as TRUE
294 if (strpos($str, 'foo') == FALSE)
Derek Jones8ede1a22011-10-05 13:34:52 -0500295
Derek Jones129c1812011-10-05 17:15:44 -0500296**CORRECT**::
297
298 if (strpos($str, 'foo') === FALSE)
299
300**INCORRECT**::
301
302 function build_string($str = "")
303 {
304 if ($str == "") // uh-oh! What if FALSE or the integer 0 is passed as an argument?
305 {
306
307 }
308 }
309
310**CORRECT**::
311
312 function build_string($str = "")
313 {
314 if ($str === "")
315 {
316
317 }
318 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500319
320
Andrey Andreev16a704c2012-11-09 17:25:00 +0200321See also information regarding `typecasting
322<http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting>`_,
Derek Jones8ede1a22011-10-05 13:34:52 -0500323which can be quite useful. Typecasting has a slightly different effect
324which may be desirable. When casting a variable as a string, for
325instance, NULL and boolean FALSE variables become empty strings, 0 (and
326other numbers) become strings of digits, and boolean TRUE becomes "1"::
327
328 $str = (string) $str; // cast $str as a string
329
330Debugging Code
331==============
332
Eric Roberts4addd5e2013-02-25 14:14:05 -0600333Do not leave debugging code in your submissions, even when commented out.
Eric Robertsd746f262013-02-25 19:55:49 -0600334Things such as ``var_dump()``, ``print_r()``, ``die()``/``exit()`` should not be included
Eric Roberts4addd5e2013-02-25 14:14:05 -0600335in your code unless it serves a specific purpose other than debugging.
Derek Jones8ede1a22011-10-05 13:34:52 -0500336
337Whitespace in Files
338===================
339
340No whitespace can precede the opening PHP tag or follow the closing PHP
341tag. Output is buffered, so whitespace in your files can cause output to
342begin before CodeIgniter outputs its content, leading to errors and an
Eric Roberts4addd5e2013-02-25 14:14:05 -0600343inability for CodeIgniter to send proper headers.
Derek Jones8ede1a22011-10-05 13:34:52 -0500344
Derek Jones8ede1a22011-10-05 13:34:52 -0500345Compatibility
346=============
347
Andrey Andreev934d6d92015-01-12 15:03:10 +0200348CodeIgniter recommends PHP 5.4 or newer to be used, but it should be
349compatible with PHP 5.2.4. Your code must either be compatible with this
350requirement, provide a suitable fallback, or be an optional feature that
351dies quietly without affecting a user's application.
Derek Jones8ede1a22011-10-05 13:34:52 -0500352
Eric Roberts4addd5e2013-02-25 14:14:05 -0600353Additionally, do not use PHP functions that require non-default libraries
354to be installed unless your code contains an alternative method when the
355function is not available.
Derek Jones129c1812011-10-05 17:15:44 -0500356
Derek Jones8ede1a22011-10-05 13:34:52 -0500357One File per Class
358==================
359
Eric Roberts4addd5e2013-02-25 14:14:05 -0600360Use separate files for each class, unless the classes are *closely related*.
Eric Robertsd746f262013-02-25 19:55:49 -0600361An example of a CodeIgniter file that contains multiple classes is the
362Xmlrpc library file.
Derek Jones8ede1a22011-10-05 13:34:52 -0500363
364Whitespace
365==========
366
367Use tabs for whitespace in your code, not spaces. This may seem like a
368small thing, but using tabs instead of whitespace allows the developer
369looking at your code to have indentation at levels that they prefer and
370customize in whatever application they use. And as a side benefit, it
371results in (slightly) more compact files, storing one tab character
372versus, say, four space characters.
373
374Line Breaks
375===========
376
377Files must be saved with Unix line breaks. This is more of an issue for
378developers who work in Windows, but in any case ensure that your text
379editor is setup to save files with Unix line breaks.
380
381Code Indenting
382==============
383
384Use Allman style indenting. With the exception of Class declarations,
385braces are always placed on a line by themselves, and indented at the
386same level as the control statement that "owns" them.
387
Derek Jones129c1812011-10-05 17:15:44 -0500388**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500389
Derek Jones129c1812011-10-05 17:15:44 -0500390 function foo($bar) {
391 // ...
392 }
393
394 foreach ($arr as $key => $val) {
395 // ...
396 }
397
398 if ($foo == $bar) {
399 // ...
400 } else {
401 // ...
402 }
403
404 for ($i = 0; $i < 10; $i++)
405 {
406 for ($j = 0; $j < 10; $j++)
407 {
408 // ...
409 }
410 }
Timothy Warren82c83072012-01-26 19:02:05 -0500411
412 try {
413 // ...
414 }
415 catch() {
416 // ...
417 }
Derek Jones129c1812011-10-05 17:15:44 -0500418
419**CORRECT**::
420
421 function foo($bar)
422 {
423 // ...
424 }
425
426 foreach ($arr as $key => $val)
427 {
428 // ...
429 }
430
431 if ($foo == $bar)
432 {
433 // ...
434 }
435 else
436 {
437 // ...
438 }
439
440 for ($i = 0; $i < 10; $i++)
441 {
442 for ($j = 0; $j < 10; $j++)
443 {
444 // ...
445 }
446 }
Timothy Warren82c83072012-01-26 19:02:05 -0500447
448 try
449 {
450 // ...
451 }
452 catch()
453 {
454 // ...
455 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500456
457Bracket and Parenthetic Spacing
458===============================
459
460In general, parenthesis and brackets should not use any additional
461spaces. The exception is that a space should always follow PHP control
462structures that accept arguments with parenthesis (declare, do-while,
463elseif, for, foreach, if, switch, while), to help distinguish them from
464functions and increase readability.
465
Derek Jones129c1812011-10-05 17:15:44 -0500466**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500467
Derek Jones129c1812011-10-05 17:15:44 -0500468 $arr[ $foo ] = 'foo';
469
470**CORRECT**::
471
472 $arr[$foo] = 'foo'; // no spaces around array keys
473
474**INCORRECT**::
475
476 function foo ( $bar )
477 {
478
479 }
480
481**CORRECT**::
482
483 function foo($bar) // no spaces around parenthesis in function declarations
484 {
485
486 }
487
488**INCORRECT**::
489
490 foreach( $query->result() as $row )
491
492**CORRECT**::
493
494 foreach ($query->result() as $row) // single space following PHP control structures, but not in interior parenthesis
Derek Jones8ede1a22011-10-05 13:34:52 -0500495
496Localized Text
497==============
498
Eric Roberts4addd5e2013-02-25 14:14:05 -0600499CodeIgniter libraries should take advantage of corresponding language files
500whenever possible.
Derek Jones8ede1a22011-10-05 13:34:52 -0500501
Derek Jones129c1812011-10-05 17:15:44 -0500502**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500503
Derek Jones129c1812011-10-05 17:15:44 -0500504 return "Invalid Selection";
505
506**CORRECT**::
507
508 return $this->lang->line('invalid_selection');
Derek Jones8ede1a22011-10-05 13:34:52 -0500509
510Private Methods and Variables
511=============================
512
Eric Roberts4addd5e2013-02-25 14:14:05 -0600513Methods and variables that are only accessed internally,
Derek Jones8ede1a22011-10-05 13:34:52 -0500514such as utility and helper functions that your public methods use for
515code abstraction, should be prefixed with an underscore.
516
517::
518
Andrey Andreev16a704c2012-11-09 17:25:00 +0200519 public function convert_text()
520 private function _convert_text()
Derek Jones8ede1a22011-10-05 13:34:52 -0500521
522PHP Errors
523==========
524
525Code must run error free and not rely on warnings and notices to be
526hidden to meet this requirement. For instance, never access a variable
Andrey Andreev16a704c2012-11-09 17:25:00 +0200527that you did not set yourself (such as ``$_POST`` array keys) without first
528checking to see that it ``isset()``.
Derek Jones8ede1a22011-10-05 13:34:52 -0500529
Eric Roberts4addd5e2013-02-25 14:14:05 -0600530Make sure that your dev environment has error reporting enabled
Derek Jones8ede1a22011-10-05 13:34:52 -0500531for ALL users, and that display_errors is enabled in the PHP
532environment. You can check this setting with::
533
Derek Jones129c1812011-10-05 17:15:44 -0500534 if (ini_get('display_errors') == 1)
535 {
536 exit "Enabled";
537 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500538
Andrey Andreev16a704c2012-11-09 17:25:00 +0200539On some servers where *display_errors* is disabled, and you do not have
Derek Jones8ede1a22011-10-05 13:34:52 -0500540the ability to change this in the php.ini, you can often enable it with::
541
542 ini_set('display_errors', 1);
543
Andrey Andreev16a704c2012-11-09 17:25:00 +0200544.. note:: Setting the `display_errors
Connor Tumbleson1d6bddd2014-01-24 07:37:22 -0600545 <http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors>`_
Andrey Andreev16a704c2012-11-09 17:25:00 +0200546 setting with ``ini_set()`` at runtime is not identical to having
547 it enabled in the PHP environment. Namely, it will not have any
548 effect if the script has fatal errors.
Derek Jones8ede1a22011-10-05 13:34:52 -0500549
550Short Open Tags
551===============
552
553Always use full PHP opening tags, in case a server does not have
Andrey Andreev16a704c2012-11-09 17:25:00 +0200554*short_open_tag* enabled.
Derek Jones8ede1a22011-10-05 13:34:52 -0500555
Derek Jones129c1812011-10-05 17:15:44 -0500556**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500557
Derek Jones129c1812011-10-05 17:15:44 -0500558 <? echo $foo; ?>
559
560 <?=$foo?>
561
562**CORRECT**::
563
564 <?php echo $foo; ?>
Derek Jones8ede1a22011-10-05 13:34:52 -0500565
Andrey Andreev16a704c2012-11-09 17:25:00 +0200566.. note:: PHP 5.4 will always have the **<?=** tag available.
567
Derek Jones8ede1a22011-10-05 13:34:52 -0500568One Statement Per Line
569======================
570
571Never combine statements on one line.
572
Derek Jones129c1812011-10-05 17:15:44 -0500573**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500574
Derek Jones129c1812011-10-05 17:15:44 -0500575 $foo = 'this'; $bar = 'that'; $bat = str_replace($foo, $bar, $bag);
576
577**CORRECT**::
578
579 $foo = 'this';
580 $bar = 'that';
581 $bat = str_replace($foo, $bar, $bag);
Derek Jones8ede1a22011-10-05 13:34:52 -0500582
583Strings
584=======
585
586Always use single quoted strings unless you need variables parsed, and
587in cases where you do need variables parsed, use braces to prevent
588greedy token parsing. You may also use double-quoted strings if the
589string contains single quotes, so you do not have to use escape
590characters.
591
Derek Jones129c1812011-10-05 17:15:44 -0500592**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500593
Derek Jones129c1812011-10-05 17:15:44 -0500594 "My String" // no variable parsing, so no use for double quotes
595 "My string $foo" // needs braces
596 'SELECT foo FROM bar WHERE baz = \'bag\'' // ugly
597
598**CORRECT**::
599
600 'My String'
601 "My string {$foo}"
602 "SELECT foo FROM bar WHERE baz = 'bag'"
Derek Jones8ede1a22011-10-05 13:34:52 -0500603
604SQL Queries
605===========
606
Andrey Andreev16a704c2012-11-09 17:25:00 +0200607SQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE,
Derek Jones8ede1a22011-10-05 13:34:52 -0500608AS, JOIN, ON, IN, etc.
609
610Break up long queries into multiple lines for legibility, preferably
611breaking for each clause.
612
Derek Jones129c1812011-10-05 17:15:44 -0500613**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500614
Derek Jones129c1812011-10-05 17:15:44 -0500615 // keywords are lowercase and query is too long for
616 // a single line (... indicates continuation of line)
617 $query = $this->db->query("select foo, bar, baz, foofoo, foobar as raboof, foobaz from exp_pre_email_addresses
618 ...where foo != 'oof' and baz != 'zab' order by foobaz limit 5, 100");
619
620**CORRECT**::
621
622 $query = $this->db->query("SELECT foo, bar, baz, foofoo, foobar AS raboof, foobaz
623 FROM exp_pre_email_addresses
624 WHERE foo != 'oof'
625 AND baz != 'zab'
626 ORDER BY foobaz
627 LIMIT 5, 100");
Derek Jones8ede1a22011-10-05 13:34:52 -0500628
629Default Function Arguments
630==========================
631
632Whenever appropriate, provide function argument defaults, which helps
633prevent PHP errors with mistaken calls and provides common fallback
634values which can save a few lines of code. Example::
635
Andrey Andreev16a704c2012-11-09 17:25:00 +0200636 function foo($bar = '', $baz = FALSE)