blob: 144b362f5813d6851b291e9effc9739aa12b5ea6 [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,
55blank pages. For this reason, all PHP files should **OMIT** the closing
56PHP tag, and instead use a comment block to mark the end of file and
Andrey Andreev93f5c5d2012-11-22 13:26:07 +020057its location relative to the application root. This allows you to still
Derek Jones8ede1a22011-10-05 13:34:52 -050058identify a file as being complete and not truncated.
59
Derek Jones129c1812011-10-05 17:15:44 -050060**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -050061
Derek Jones129c1812011-10-05 17:15:44 -050062 <?php
63
64 echo "Here's my code!";
65
66 ?>
67
68**CORRECT**::
69
70 <?php
71
72 echo "Here's my code!";
73
74 /* End of file myfile.php */
75 /* Location: ./system/modules/mymodule/myfile.php */
Derek Jones8ede1a22011-10-05 13:34:52 -050076
Eric Roberts4addd5e2013-02-25 14:14:05 -060077.. note:: There should be no empty line or newline character(s) following
78 the closing comments. If you happen to see one when
79 submitting a pull request, please check your IDE settings and fix it.
80
Derek Jones8ede1a22011-10-05 13:34:52 -050081Class and Method Naming
82=======================
83
84Class names should always start with an uppercase letter. Multiple words
Eric Roberts4addd5e2013-02-25 14:14:05 -060085should be separated with an underscore, and not CamelCased.
Derek Jones8ede1a22011-10-05 13:34:52 -050086
Derek Jones129c1812011-10-05 17:15:44 -050087**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -050088
Derek Jones129c1812011-10-05 17:15:44 -050089 class superclass
90 class SuperClass
91
92**CORRECT**::
93
94 class Super_class
Derek Jones8ede1a22011-10-05 13:34:52 -050095
96::
97
Derek Jones129c1812011-10-05 17:15:44 -050098 class Super_class {
Derek Jones8ede1a22011-10-05 13:34:52 -050099
Andrey Andreevd8e1ac72012-03-26 22:22:37 +0300100 public function __construct()
Derek Jones129c1812011-10-05 17:15:44 -0500101 {
Derek Jones8ede1a22011-10-05 13:34:52 -0500102
Derek Jones129c1812011-10-05 17:15:44 -0500103 }
104 }
105
Eric Roberts4addd5e2013-02-25 14:14:05 -0600106Class methods should be entirely lowercased and named to clearly
107indicate their function, preferably including a verb. Try to avoid
Eric Robertsd746f262013-02-25 19:55:49 -0600108overly long and verbose names. Multiple words should be separated
109with an underscore.
Derek Jones129c1812011-10-05 17:15:44 -0500110
111**INCORRECT**::
112
113 function fileproperties() // not descriptive and needs underscore separator
114 function fileProperties() // not descriptive and uses CamelCase
115 function getfileproperties() // Better! But still missing underscore separator
116 function getFileProperties() // uses CamelCase
117 function get_the_file_properties_from_the_file() // wordy
118
119**CORRECT**::
120
121 function get_file_properties() // descriptive, underscore separator, and all lowercase letters
Derek Jones8ede1a22011-10-05 13:34:52 -0500122
123Variable Names
124==============
125
Eric Roberts4addd5e2013-02-25 14:14:05 -0600126The guidelines for variable naming are very similar to those used for
127class methods. Variables should contain only lowercase letters,
Derek Jones8ede1a22011-10-05 13:34:52 -0500128use underscore separators, and be reasonably named to indicate their
129purpose and contents. Very short, non-word variables should only be used
130as iterators in for() loops.
131
Derek Jones129c1812011-10-05 17:15:44 -0500132**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500133
Derek Jones129c1812011-10-05 17:15:44 -0500134 $j = 'foo'; // single letter variables should only be used in for() loops
135 $Str // contains uppercase letters
136 $bufferedText // uses CamelCasing, and could be shortened without losing semantic meaning
137 $groupid // multiple words, needs underscore separator
138 $name_of_last_city_used // too long
139
140**CORRECT**::
141
142 for ($j = 0; $j < 10; $j++)
143 $str
144 $buffer
145 $group_id
146 $last_city
Derek Jones8ede1a22011-10-05 13:34:52 -0500147
148Commenting
149==========
150
151In general, code should be commented prolifically. It not only helps
152describe the flow and intent of the code for less experienced
153programmers, but can prove invaluable when returning to your own code
154months down the line. There is not a required format for comments, but
155the following are recommended.
156
157`DocBlock <http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblock>`_
Timothy Warrenbb8ae012012-04-20 10:31:51 -0400158style comments preceding class, method, and property declarations so they can be
Derek Jones8ede1a22011-10-05 13:34:52 -0500159picked up by IDEs::
160
Derek Jones129c1812011-10-05 17:15:44 -0500161 /**
162 * Super Class
163 *
164 * @package Package Name
165 * @subpackage Subpackage
166 * @category Category
167 * @author Author Name
168 * @link http://example.com
169 */
170 class Super_class {
Derek Jones8ede1a22011-10-05 13:34:52 -0500171
172::
173
Derek Jones129c1812011-10-05 17:15:44 -0500174 /**
175 * Encodes string for use in XML
176 *
Andrey Andreev16a704c2012-11-09 17:25:00 +0200177 * @param string $str Input string
Derek Jones129c1812011-10-05 17:15:44 -0500178 * @return string
179 */
180 function xml_encode($str)
Andrey Andreev16a704c2012-11-09 17:25:00 +0200181
Timothy Warrenbb8ae012012-04-20 10:31:51 -0400182::
183
184 /**
185 * Data for class manipulation
186 *
187 * @var array
188 */
Andrey Andreev16a704c2012-11-09 17:25:00 +0200189 public $data = array();
Derek Jones8ede1a22011-10-05 13:34:52 -0500190
191Use single line comments within code, leaving a blank line between large
192comment blocks and code.
193
194::
195
Derek Jones129c1812011-10-05 17:15:44 -0500196 // break up the string by newlines
197 $parts = explode("\n", $str);
198
199 // A longer comment that needs to give greater detail on what is
200 // occurring and why can use multiple single-line comments. Try to
201 // keep the width reasonable, around 70 characters is the easiest to
202 // read. Don't hesitate to link to permanent external resources
203 // that may provide greater detail:
204 //
205 // http://example.com/information_about_something/in_particular/
206
207 $parts = $this->foo($parts);
Derek Jones8ede1a22011-10-05 13:34:52 -0500208
209Constants
210=========
211
212Constants follow the same guidelines as do variables, except constants
213should always be fully uppercase. *Always use CodeIgniter constants when
214appropriate, i.e. SLASH, LD, RD, PATH_CACHE, etc.*
215
Derek Jones129c1812011-10-05 17:15:44 -0500216**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500217
Derek Jones129c1812011-10-05 17:15:44 -0500218 myConstant // missing underscore separator and not fully uppercase
219 N // no single-letter constants
220 S_C_VER // not descriptive
221 $str = str_replace('{foo}', 'bar', $str); // should use LD and RD constants
222
223**CORRECT**::
224
225 MY_CONSTANT
226 NEWLINE
227 SUPER_CLASS_VERSION
228 $str = str_replace(LD.'foo'.RD, 'bar', $str);
Derek Jones8ede1a22011-10-05 13:34:52 -0500229
230TRUE, FALSE, and NULL
231=====================
232
233**TRUE**, **FALSE**, and **NULL** keywords should always be fully
234uppercase.
235
Derek Jones129c1812011-10-05 17:15:44 -0500236**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500237
Derek Jones129c1812011-10-05 17:15:44 -0500238 if ($foo == true)
239 $bar = false;
240 function foo($bar = null)
241
242**CORRECT**::
243
244 if ($foo == TRUE)
245 $bar = FALSE;
246 function foo($bar = NULL)
Derek Jones8ede1a22011-10-05 13:34:52 -0500247
248Logical Operators
249=================
250
Eric Robertsd746f262013-02-25 19:55:49 -0600251Use of the ``||`` "or" comparison operator is discouraged, as its clarity
Eric Roberts4addd5e2013-02-25 14:14:05 -0600252on some output devices is low (looking like the number 11, for instance).
Eric Robertsd746f262013-02-25 19:55:49 -0600253``&&`` is preferred over ``AND`` but either are acceptable, and a space should
254always precede and follow ``!``.
Derek Jones8ede1a22011-10-05 13:34:52 -0500255
Derek Jones129c1812011-10-05 17:15:44 -0500256**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500257
Derek Jones129c1812011-10-05 17:15:44 -0500258 if ($foo || $bar)
259 if ($foo AND $bar) // okay but not recommended for common syntax highlighting applications
260 if (!$foo)
261 if (! is_array($foo))
262
263**CORRECT**::
264
265 if ($foo OR $bar)
266 if ($foo && $bar) // recommended
267 if ( ! $foo)
268 if ( ! is_array($foo))
269
Derek Jones8ede1a22011-10-05 13:34:52 -0500270
271Comparing Return Values and Typecasting
272=======================================
273
274Some PHP functions return FALSE on failure, but may also have a valid
275return value of "" or 0, which would evaluate to FALSE in loose
276comparisons. Be explicit by comparing the variable type when using these
277return values in conditionals to ensure the return value is indeed what
278you expect, and not a value that has an equivalent loose-type
279evaluation.
280
281Use the same stringency in returning and checking your own variables.
282Use **===** and **!==** as necessary.
Derek Jones8ede1a22011-10-05 13:34:52 -0500283
Derek Jones129c1812011-10-05 17:15:44 -0500284**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500285
Derek Jones129c1812011-10-05 17:15:44 -0500286 // If 'foo' is at the beginning of the string, strpos will return a 0,
287 // resulting in this conditional evaluating as TRUE
288 if (strpos($str, 'foo') == FALSE)
Derek Jones8ede1a22011-10-05 13:34:52 -0500289
Derek Jones129c1812011-10-05 17:15:44 -0500290**CORRECT**::
291
292 if (strpos($str, 'foo') === FALSE)
293
294**INCORRECT**::
295
296 function build_string($str = "")
297 {
298 if ($str == "") // uh-oh! What if FALSE or the integer 0 is passed as an argument?
299 {
300
301 }
302 }
303
304**CORRECT**::
305
306 function build_string($str = "")
307 {
308 if ($str === "")
309 {
310
311 }
312 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500313
314
Andrey Andreev16a704c2012-11-09 17:25:00 +0200315See also information regarding `typecasting
316<http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting>`_,
Derek Jones8ede1a22011-10-05 13:34:52 -0500317which can be quite useful. Typecasting has a slightly different effect
318which may be desirable. When casting a variable as a string, for
319instance, NULL and boolean FALSE variables become empty strings, 0 (and
320other numbers) become strings of digits, and boolean TRUE becomes "1"::
321
322 $str = (string) $str; // cast $str as a string
323
324Debugging Code
325==============
326
Eric Roberts4addd5e2013-02-25 14:14:05 -0600327Do not leave debugging code in your submissions, even when commented out.
Eric Robertsd746f262013-02-25 19:55:49 -0600328Things such as ``var_dump()``, ``print_r()``, ``die()``/``exit()`` should not be included
Eric Roberts4addd5e2013-02-25 14:14:05 -0600329in your code unless it serves a specific purpose other than debugging.
Derek Jones8ede1a22011-10-05 13:34:52 -0500330
331Whitespace in Files
332===================
333
334No whitespace can precede the opening PHP tag or follow the closing PHP
335tag. Output is buffered, so whitespace in your files can cause output to
336begin before CodeIgniter outputs its content, leading to errors and an
Eric Roberts4addd5e2013-02-25 14:14:05 -0600337inability for CodeIgniter to send proper headers.
Derek Jones8ede1a22011-10-05 13:34:52 -0500338
Derek Jones8ede1a22011-10-05 13:34:52 -0500339Compatibility
340=============
341
Eric Roberts4addd5e2013-02-25 14:14:05 -0600342CodeIgniter requires a minimum PHP version of 5.2.4. Your code must either
343be compatible with this minimum requirement, provide a suitable fallback,
344or be an optional feature that dies quietly without affecting a user's
345application.
Derek Jones8ede1a22011-10-05 13:34:52 -0500346
Eric Roberts4addd5e2013-02-25 14:14:05 -0600347Additionally, do not use PHP functions that require non-default libraries
348to be installed unless your code contains an alternative method when the
349function is not available.
Derek Jones129c1812011-10-05 17:15:44 -0500350
Derek Jones8ede1a22011-10-05 13:34:52 -0500351One File per Class
352==================
353
Eric Roberts4addd5e2013-02-25 14:14:05 -0600354Use separate files for each class, unless the classes are *closely related*.
Eric Robertsd746f262013-02-25 19:55:49 -0600355An example of a CodeIgniter file that contains multiple classes is the
356Xmlrpc library file.
Derek Jones8ede1a22011-10-05 13:34:52 -0500357
358Whitespace
359==========
360
361Use tabs for whitespace in your code, not spaces. This may seem like a
362small thing, but using tabs instead of whitespace allows the developer
363looking at your code to have indentation at levels that they prefer and
364customize in whatever application they use. And as a side benefit, it
365results in (slightly) more compact files, storing one tab character
366versus, say, four space characters.
367
368Line Breaks
369===========
370
371Files must be saved with Unix line breaks. This is more of an issue for
372developers who work in Windows, but in any case ensure that your text
373editor is setup to save files with Unix line breaks.
374
375Code Indenting
376==============
377
378Use Allman style indenting. With the exception of Class declarations,
379braces are always placed on a line by themselves, and indented at the
380same level as the control statement that "owns" them.
381
Derek Jones129c1812011-10-05 17:15:44 -0500382**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500383
Derek Jones129c1812011-10-05 17:15:44 -0500384 function foo($bar) {
385 // ...
386 }
387
388 foreach ($arr as $key => $val) {
389 // ...
390 }
391
392 if ($foo == $bar) {
393 // ...
394 } else {
395 // ...
396 }
397
398 for ($i = 0; $i < 10; $i++)
399 {
400 for ($j = 0; $j < 10; $j++)
401 {
402 // ...
403 }
404 }
Timothy Warren82c83072012-01-26 19:02:05 -0500405
406 try {
407 // ...
408 }
409 catch() {
410 // ...
411 }
Derek Jones129c1812011-10-05 17:15:44 -0500412
413**CORRECT**::
414
415 function foo($bar)
416 {
417 // ...
418 }
419
420 foreach ($arr as $key => $val)
421 {
422 // ...
423 }
424
425 if ($foo == $bar)
426 {
427 // ...
428 }
429 else
430 {
431 // ...
432 }
433
434 for ($i = 0; $i < 10; $i++)
435 {
436 for ($j = 0; $j < 10; $j++)
437 {
438 // ...
439 }
440 }
Timothy Warren82c83072012-01-26 19:02:05 -0500441
442 try
443 {
444 // ...
445 }
446 catch()
447 {
448 // ...
449 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500450
451Bracket and Parenthetic Spacing
452===============================
453
454In general, parenthesis and brackets should not use any additional
455spaces. The exception is that a space should always follow PHP control
456structures that accept arguments with parenthesis (declare, do-while,
457elseif, for, foreach, if, switch, while), to help distinguish them from
458functions and increase readability.
459
Derek Jones129c1812011-10-05 17:15:44 -0500460**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500461
Derek Jones129c1812011-10-05 17:15:44 -0500462 $arr[ $foo ] = 'foo';
463
464**CORRECT**::
465
466 $arr[$foo] = 'foo'; // no spaces around array keys
467
468**INCORRECT**::
469
470 function foo ( $bar )
471 {
472
473 }
474
475**CORRECT**::
476
477 function foo($bar) // no spaces around parenthesis in function declarations
478 {
479
480 }
481
482**INCORRECT**::
483
484 foreach( $query->result() as $row )
485
486**CORRECT**::
487
488 foreach ($query->result() as $row) // single space following PHP control structures, but not in interior parenthesis
Derek Jones8ede1a22011-10-05 13:34:52 -0500489
490Localized Text
491==============
492
Eric Roberts4addd5e2013-02-25 14:14:05 -0600493CodeIgniter libraries should take advantage of corresponding language files
494whenever possible.
Derek Jones8ede1a22011-10-05 13:34:52 -0500495
Derek Jones129c1812011-10-05 17:15:44 -0500496**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500497
Derek Jones129c1812011-10-05 17:15:44 -0500498 return "Invalid Selection";
499
500**CORRECT**::
501
502 return $this->lang->line('invalid_selection');
Derek Jones8ede1a22011-10-05 13:34:52 -0500503
504Private Methods and Variables
505=============================
506
Eric Roberts4addd5e2013-02-25 14:14:05 -0600507Methods and variables that are only accessed internally,
Derek Jones8ede1a22011-10-05 13:34:52 -0500508such as utility and helper functions that your public methods use for
509code abstraction, should be prefixed with an underscore.
510
511::
512
Andrey Andreev16a704c2012-11-09 17:25:00 +0200513 public function convert_text()
514 private function _convert_text()
Derek Jones8ede1a22011-10-05 13:34:52 -0500515
516PHP Errors
517==========
518
519Code must run error free and not rely on warnings and notices to be
520hidden to meet this requirement. For instance, never access a variable
Andrey Andreev16a704c2012-11-09 17:25:00 +0200521that you did not set yourself (such as ``$_POST`` array keys) without first
522checking to see that it ``isset()``.
Derek Jones8ede1a22011-10-05 13:34:52 -0500523
Eric Roberts4addd5e2013-02-25 14:14:05 -0600524Make sure that your dev environment has error reporting enabled
Derek Jones8ede1a22011-10-05 13:34:52 -0500525for ALL users, and that display_errors is enabled in the PHP
526environment. You can check this setting with::
527
Derek Jones129c1812011-10-05 17:15:44 -0500528 if (ini_get('display_errors') == 1)
529 {
530 exit "Enabled";
531 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500532
Andrey Andreev16a704c2012-11-09 17:25:00 +0200533On some servers where *display_errors* is disabled, and you do not have
Derek Jones8ede1a22011-10-05 13:34:52 -0500534the ability to change this in the php.ini, you can often enable it with::
535
536 ini_set('display_errors', 1);
537
Andrey Andreev16a704c2012-11-09 17:25:00 +0200538.. note:: Setting the `display_errors
539 <http://php.net/manual/en/ref.errorfunc.php#ini.display-errors>`_
540 setting with ``ini_set()`` at runtime is not identical to having
541 it enabled in the PHP environment. Namely, it will not have any
542 effect if the script has fatal errors.
Derek Jones8ede1a22011-10-05 13:34:52 -0500543
544Short Open Tags
545===============
546
547Always use full PHP opening tags, in case a server does not have
Andrey Andreev16a704c2012-11-09 17:25:00 +0200548*short_open_tag* enabled.
Derek Jones8ede1a22011-10-05 13:34:52 -0500549
Derek Jones129c1812011-10-05 17:15:44 -0500550**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500551
Derek Jones129c1812011-10-05 17:15:44 -0500552 <? echo $foo; ?>
553
554 <?=$foo?>
555
556**CORRECT**::
557
558 <?php echo $foo; ?>
Derek Jones8ede1a22011-10-05 13:34:52 -0500559
Andrey Andreev16a704c2012-11-09 17:25:00 +0200560.. note:: PHP 5.4 will always have the **<?=** tag available.
561
Derek Jones8ede1a22011-10-05 13:34:52 -0500562One Statement Per Line
563======================
564
565Never combine statements on one line.
566
Derek Jones129c1812011-10-05 17:15:44 -0500567**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500568
Derek Jones129c1812011-10-05 17:15:44 -0500569 $foo = 'this'; $bar = 'that'; $bat = str_replace($foo, $bar, $bag);
570
571**CORRECT**::
572
573 $foo = 'this';
574 $bar = 'that';
575 $bat = str_replace($foo, $bar, $bag);
Derek Jones8ede1a22011-10-05 13:34:52 -0500576
577Strings
578=======
579
580Always use single quoted strings unless you need variables parsed, and
581in cases where you do need variables parsed, use braces to prevent
582greedy token parsing. You may also use double-quoted strings if the
583string contains single quotes, so you do not have to use escape
584characters.
585
Derek Jones129c1812011-10-05 17:15:44 -0500586**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500587
Derek Jones129c1812011-10-05 17:15:44 -0500588 "My String" // no variable parsing, so no use for double quotes
589 "My string $foo" // needs braces
590 'SELECT foo FROM bar WHERE baz = \'bag\'' // ugly
591
592**CORRECT**::
593
594 'My String'
595 "My string {$foo}"
596 "SELECT foo FROM bar WHERE baz = 'bag'"
Derek Jones8ede1a22011-10-05 13:34:52 -0500597
598SQL Queries
599===========
600
Andrey Andreev16a704c2012-11-09 17:25:00 +0200601SQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE,
Derek Jones8ede1a22011-10-05 13:34:52 -0500602AS, JOIN, ON, IN, etc.
603
604Break up long queries into multiple lines for legibility, preferably
605breaking for each clause.
606
Derek Jones129c1812011-10-05 17:15:44 -0500607**INCORRECT**::
Derek Jones8ede1a22011-10-05 13:34:52 -0500608
Derek Jones129c1812011-10-05 17:15:44 -0500609 // keywords are lowercase and query is too long for
610 // a single line (... indicates continuation of line)
611 $query = $this->db->query("select foo, bar, baz, foofoo, foobar as raboof, foobaz from exp_pre_email_addresses
612 ...where foo != 'oof' and baz != 'zab' order by foobaz limit 5, 100");
613
614**CORRECT**::
615
616 $query = $this->db->query("SELECT foo, bar, baz, foofoo, foobar AS raboof, foobaz
617 FROM exp_pre_email_addresses
618 WHERE foo != 'oof'
619 AND baz != 'zab'
620 ORDER BY foobaz
621 LIMIT 5, 100");
Derek Jones8ede1a22011-10-05 13:34:52 -0500622
623Default Function Arguments
624==========================
625
626Whenever appropriate, provide function argument defaults, which helps
627prevent PHP errors with mistaken calls and provides common fallback
628values which can save a few lines of code. Example::
629
Andrey Andreev16a704c2012-11-09 17:25:00 +0200630 function foo($bar = '', $baz = FALSE)