<p>In order to make this as simple as possible, we will be using tabs, not spaces. We enforce 4 (four) spaces for one tab - therefore you need to set your tab width within your editor to 4 spaces. Make sure that when you <strong>save</strong> the file, it's saving tabs and not spaces. This way, we can each have the code be displayed the way we like it, without breaking the layout of the actual files.</p>
<p>Tabs in front of lines are no problem, but having them within the text can be a problem if you do not set it to the amount of spaces every one of us uses. Here is a short example of how it should look like:</p>
<p>If entered with tabs (replace the {TAB}) both equal signs need to be on the same column.</p>
<h3>Linefeeds:</h3>
<p>Ensure that your editor is saving files in the UNIX (LF) line ending format. This means that lines are terminated with a newline, not with Windows Line endings (CR/LF combo) as they are on Win32 or Classic Mac (CR) Line endings. Any decent editor should be able to do this, but it might not always be the default setting. Know your editor. If you want advice for an editor for your Operating System, just ask one of the developers. Some of them do their editing on Win32.</p>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
</pre></div>
<p>Please see the <ahref="#locations">File Locations section</a> for the correct package name.</p>
<h4>PHP closing tags</h4>
<p>A file containg only PHP code should not end with the optional PHP closing tag <strong>?></strong> to avoid issues with whitespace following it.</p>
<h4>Newline at end of file</h4>
<p>All files should end in a newline so the last line does not appear as modified in diffs, when a line is appended to the file.</p>
<h4>Files containing inline code:</h4>
<p>For those files you have to put an empty comment directly after the header to prevent the documentor assigning the header to the first code element found.</p>
<divclass="codebox"><pre>
/**
* {HEADER}
*/
/**
*/
{CODE}
</pre></div>
<h4>Files containing only functions:</h4>
<p>Do not forget to comment the functions (especially the first function following the header). Each function should have at least a comment of what this function does. For more complex functions it is recommended to document the parameters too.</p>
<h4>Files containing only classes:</h4>
<p>Do not forget to comment the class. Classes need a separate @package definition, it is the same as the header package name. Apart from this special case the above statement for files containing only functions needs to be applied to classes and it's methods too.</p>
<h4>Code following the header but only functions/classes file:</h4>
<p>If this case is true, the best method to avoid documentation confusions is adding an ignore command, for example:</p>
<divclass="codebox"><pre>
/**
* {HEADER}
*/
/**
* @ignore
*/
Small code snipped, mostly one or two defines or an if statement
<p>Functions used by more than one page should be placed in functions.php, functions specific to one page should be placed on that page (at the bottom) or within the relevant sections functions file. Some files in <code>/includes</code> are holding functions responsible for special sections, for example uploading files, displaying "things", user related functions and so forth.</p>
<p>The following packages are defined, and related new features/functions should be placed within the mentioned files/locations, as well as specifying the correct package name. The package names are bold within this list:</p>
<ul>
<li><strong>phpBB3</strong><br/>Core files and all files not assigned to a separate package</li>
<li><strong>acp</strong><br/><code>/adm</code>, <code>/includes/acp</code>, <code>/includes/functions_admin.php</code><br/>Administration Control Panel</li>
PHPBB_QA (Set board to QA-Mode, which means the updater also checks for RC-releases)
</pre></div>
<h4>PHPBB_USE_BOARD_URL_PATH</h4>
<p>If the <code>PHPBB_USE_BOARD_URL_PATH</code> constant is set to true, phpBB uses generate_board_url() (this will return the boards url with the script path included) on all instances where web-accessible images are loaded. The exact locations are:</p>
<p>We will not be using any form of hungarian notation in our naming conventions. Many of us believe that hungarian naming is one of the primary code obfuscation techniques currently in use.</p>
<h4>Variable Names:</h4>
<p>In PHP, variable names should be in all lowercase, with words separated by an underscore, example:</p>
<divclass="indent">
<p><code>$current_user</code> is right, but <code>$currentuser</code> and <code> $currentUser</code> are not.</p>
</div>
<p>In JavaScript, variable names should use camel case:</p>
<divclass="indent">
<p><code>currentUser</code> is right, but <code>currentuser</code> and <code>current_user</code> are not.</p>
</div>
<p>Names should be descriptive, but concise. We don't want huge sentences as our variable names, but typing an extra couple of characters is always better than wondering what exactly a certain variable is for. </p>
<h4>Loop Indices:</h4>
<p>The <em>only</em> situation where a one-character variable name is allowed is when it's the index for some looping construct. In this case, the index of the outer loop should always be $i. If there's a loop inside that loop, its index should be $j, followed by $k, and so on. If the loop is being indexed by some already-existing variable with a meaningful name, this guideline does not apply, example:</p>
<divclass="codebox"><pre>
for ($i = 0; $i < $outer_size; $i++)
{
for ($j = 0; $j < $inner_size; $j++)
{
foo($i, $j);
}
}
</pre></div>
<h4>Function Names:</h4>
<p>Functions should also be named descriptively. We're not programming in C here, we don't want to write functions called things like "stristr()". Again, all lower-case names with words separated by a single underscore character in PHP, and camel caps in JavaScript. Function names should be prefixed with "phpbb_" and preferably have a verb in them somewhere. Good function names are <code>phpbb_print_login_status()</code>, <code>phpbb_get_user_data()</code>, etc. Constructor functions in JavaScript should begin with a capital letter.</p>
<h4>Function Arguments:</h4>
<p>Arguments are subject to the same guidelines as variable names. We don't want a bunch of functions like: <code>do_stuff($a, $b, $c)</code>. In most cases, we'd like to be able to tell how to use a function by just looking at its declaration. </p>
<h4>Class Names:</h4>
<p>Apart from following the rules for function names, all classes should meet the following conditions:</p>
<ul>
<li>Every class must be defined in a separate file.</li>
<li>The classes have to be located in a subdirectory of <code>phpbb/</code>.</li>
<li>Classnames must be namespaced with <code>\phpbb\</code> to avoid name clashes.</li>
<li>Class names/namespaces have to reflect the location of the file they are defined in. The namespace must be the directory in which the file is located. So the directory names must not contain any underscores, but the filename may.</li>
<li>Directories should typically be a singular noun (e.g. <code>dir</code> in the example below, not <code>dirs</code>.</li>
</ul>
<p>So given the following example directory structure you would result in the below listed lookups</p>
<p>The basic philosophy here is to not hurt code clarity for the sake of laziness. This has to be balanced by a little bit of common sense, though; <code>phpbb_print_login_status_for_a_given_user()</code> goes too far, for example -- that function would be better named <code>phpbb_print_user_login_status()</code>, or just <code>phpbb_print_login_status()</code>.</p>
<h4>Special Namings: </h4>
<p>For all emoticons use the term <code>smiley</code> in singular and <code>smilies</code> in plural. For emails we use the term <code>email</code> (without dash between “e” and “m”).</p>
<p>This is another case of being too lazy to type 2 extra characters causing problems with code clarity. Even if the body of some construct is only one line long, do <em>not</em> drop the braces. Just don't, examples:</p>
<pclass="bad">// These are all wrong. </p>
<divclass="codebox"><pre>
if (condition) do_stuff();
if (condition)
do_stuff();
while (condition)
do_stuff();
for ($i = 0; $i < size; $i++)
do_stuff($i);
</pre></div>
<pclass="good">// These are all right. </p>
<divclass="codebox"><pre>
if (condition)
{
do_stuff();
}
while (condition)
{
do_stuff();
}
for ($i = 0; $i < size; $i++)
{
do_stuff();
}
</pre></div>
<h4>Where to put the braces:</h4>
<p>In PHP code, braces always go on their own line. The closing brace should also always be at the same column as the corresponding opening brace, examples:</p>
<divclass="codebox"><pre>
if (condition)
{
while (condition2)
{
...
}
}
else
{
...
}
for ($i = 0; $i < $size; $i++)
{
...
}
while (condition)
{
...
}
function do_stuff()
{
...
}
</pre></div>
<p>In JavaScript code, braces always go on the same line:</p>
<divclass="codebox"><pre>
if (condition) {
while (condition2) {
...
}
} else {
...
}
for (var i = 0; i < size; i++) {
...
}
while (condition) {
...
}
function do_stuff() {
...
}
</pre></div>
<h4>Use spaces between tokens:</h4>
<p>This is another simple, easy step that helps keep code readable without much effort. Whenever you write an assignment, expression, etc.. Always leave <em>one</em> space between the tokens. Basically, write code as if it was English. Put spaces between variable names and operators. Don't put spaces just after an opening bracket or before a closing bracket. Don't put spaces just before a comma or a semicolon. This is best shown with a few examples, examples:</p>
<p>// Each pair shows the wrong way followed by the right way. </p>
<divclass="codebox"><pre>
$i=0;
$i = 0;
if($i<7) ...
if ($i < 7) ...
if ( ($i < 7)&&($j > 8) ) ...
if ($i < 7 && $j > 8) ...
do_stuff( $i, 'foo', $b );
do_stuff($i, 'foo', $b);
for($i=0; $i<$size; $i++) ...
for ($i = 0; $i < $size; $i++) ...
$i=($j < $size)?0:1;
$i = ($j < $size) ? 0 : 1;
</pre></div>
<h4>Operator precedence:</h4>
<p>Do you know the exact precedence of all the operators in PHP? Neither do I. Don't guess. Always make it obvious by using brackets to force the precedence of an equation so you know what it does. Remember to not over-use this, as it may harden the readability. Basically, do not enclose single expressions. Examples:</p>
<pclass="bad">// what's the result? who knows. </p>
<p>There are two different ways to quote strings in PHP - either with single quotes or with double quotes. The main difference is that the parser does variable interpolation in double-quoted strings, but not in single quoted strings. Because of this, you should <em>always</em> use single quotes <em>unless</em> you specifically need variable interpolation to be done on that string. This way, we can save the parser the trouble of parsing a bunch of strings where no interpolation needs to be done.</p>
<p>Also, if you are using a string variable as part of a function call, you do not need to enclose that variable in quotes. Again, this will just make unnecessary work for the parser. Note, however, that nearly all of the escape sequences that exist for double-quoted strings will not work with single-quoted strings. Be careful, and feel free to break this guideline if it's making your code easier to read, examples:</p>
<pclass="bad">// wrong </p>
<divclass="codebox"><pre>
$str = "This is a really long string with no variables for the parser to find.";
do_stuff("$str");
</pre></div>
<pclass="good">// right</p>
<divclass="codebox"><pre>
$str = 'This is a really long string with no variables for the parser to find.';
do_stuff($str);
</pre></div>
<pclass="bad">// Sometimes single quotes are just not right</p>
<p>In SQL statements mixing single and double quotes is partly allowed (following the guidelines listed here about SQL formatting), else one should try to only use one method - mostly single quotes.</p>
<h4>Commas after every array element:</h4>
<p>If an array is defined with each element on its own line, you still have to modify the previous line to add a comma when appending a new element. PHP allows for trailing (useless) commas in array definitions. These should always be used so each element including the comma can be appended with a single line. In JavaScript, do not use the trailing comma, as it causes browsers to throw errors.</p>
<pclass="bad">// wrong</p>
<divclass="codebox"><pre>
$foo = array(
'bar' => 42,
'boo' => 23
);
</pre></div>
<pclass="good">// right </p>
<divclass="codebox"><pre>
$foo = array(
'bar' => 42,
'boo' => 23,
);
</pre></div>
<h4>Associative array keys:</h4>
<p>In PHP, it's legal to use a literal string as a key to an associative array without quoting that string. We don't want to do this -- the string should always be quoted to avoid confusion. Note that this is only when we're using a literal, not when we're using a variable, examples:</p>
<pclass="bad">// wrong</p>
<divclass="codebox"><pre>
$foo = $assoc_array[blah];
</pre></div>
<pclass="good">// right </p>
<divclass="codebox"><pre>
$foo = $assoc_array['blah'];
</pre></div>
<pclass="bad">// wrong</p>
<divclass="codebox"><pre>
$foo = $assoc_array["$var"];
</pre></div>
<pclass="good">// right </p>
<divclass="codebox"><pre>
$foo = $assoc_array[$var];
</pre></div>
<h4>Comments:</h4>
<p>Each complex function should be preceded by a comment that tells a programmer everything they need to know to use that function. The meaning of every parameter, the expected input, and the output are required as a minimal comment. The function's behaviour in error conditions (and what those error conditions are) should also be present - but mostly included within the comment about the output.<br/><br/>Especially important to document are any assumptions the code makes, or preconditions for its proper operation. Any one of the developers should be able to look at any part of the application and figure out what's going on in a reasonable amount of time.<br/><br/>Avoid using <code>/* */</code> comment blocks for one-line comments, <code>//</code> should be used for one/two-liners.</p>
<h4>Magic numbers:</h4>
<p>Don't use them. Use named constants for any literal value other than obvious special cases. Basically, it's ok to check if an array has 0 elements by using the literal 0. It's not ok to assign some special meaning to a number and then use it everywhere as a literal. This hurts readability AND maintainability. The constants <code>true</code> and <code>false</code> should be used in place of the literals 1 and 0 -- even though they have the same values (but not type!), it's more obvious what the actual logic is when you use the named constants. Typecast variables where it is needed, do not rely on the correct variable type (PHP is currently very loose on typecasting which can lead to security problems if a developer does not keep a very close eye on it).</p>
<h4>Shortcut operators:</h4>
<p>The only shortcut operators that cause readability problems are the shortcut increment <code>$i++</code> and decrement <code>$j--</code> operators. These operators should not be used as part of an expression. They can, however, be used on their own line. Using them in expressions is just not worth the headaches when debugging, examples:</p>
<pclass="bad">// wrong </p>
<divclass="codebox"><pre>
$array[++$i] = $j;
$array[$i++] = $k;
</pre></div>
<pclass="good">// right </p>
<divclass="codebox"><pre>
$i++;
$array[$i] = $j;
$array[$i] = $k;
$i++;
</pre></div>
<h4>Inline conditionals:</h4>
<p>Inline conditionals should only be used to do very simple things. Preferably, they will only be used to do assignments, and not for function calls or anything complex at all. They can be harmful to readability if used incorrectly, so don't fall in love with saving typing by using them, examples:</p>
<p>For phpBB3, we intend to use a higher level of run-time error reporting. This will mean that the use of an uninitialized variable will be reported as a warning. These warnings can be avoided by using the built-in isset() function to check whether a variable has been set - but preferably the variable is always existing. For checking if an array has a key set this can come in handy though, examples:</p>
<pclass="bad">// Wrong </p>
<divclass="codebox"><pre>
if ($forum) ...
</pre></div>
<pclass="good">// Right </p>
<divclass="codebox"><pre>
if (isset($forum)) ...
</pre></div>
<pclass="good">// Also possible</p>
<divclass="codebox"><pre>
if (isset($forum) && $forum == 5)
</pre></div>
<p>The <code>empty()</code> function is useful if you want to check if a variable is not set or being empty (an empty string, 0 as an integer or string, NULL, false, an empty array or a variable declared, but without a value in a class). Therefore empty should be used in favor of <code>isset($array) && sizeof($array) > 0</code> - this can be written in a shorter way as <code>!empty($array)</code>.</p>
<h4>Switch statements:</h4>
<p>Switch/case code blocks can get a bit long sometimes. To have some level of notice and being in-line with the opening/closing brace requirement (where they are on the same line for better readability), this also applies to switch/case code blocks and the breaks. An example:</p>
<pclass="bad">// Wrong </p>
<divclass="codebox"><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
}
</pre></div>
<pclass="good">// Good </p>
<divclass="codebox"><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that a case was not caught
break;
}
</pre></div>
<pclass="good">// Also good, if you have more code between the case and the break </p>
<divclass="codebox"><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that a case was not caught
break;
}
</pre></div>
<p>Even if the break for the default case is not needed, it is sometimes better to include it just for readability and completeness.</p>
<p>If no break is intended, please add a comment instead. An example:</p>
<pclass="good">// Example with no break </p>
<divclass="codebox"><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
// no break here
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that a case was not caught
break;
}
</pre></div>
<h4>Class Members</h4>
<p>Use the explicit visibility qualifiers <code>public</code>, <code>private</code> and <code>protected</code> for all properties instead of <code>var</code>.
<p>Place the <code>static</code> qualifier before the visibility qualifiers.</p>
<pclass="bad">//Wrong </p>
<divclass="codebox"><pre>
var $x;
private static function f()
</pre></div>
<pclass="good">// Right </p>
<divclass="codebox"><pre>
public $x;
static private function f()
</pre></div>
<h4>Constants</h4>
<p>Prefer class constants over global constants created with <code>define()</code>.</p>
<aname="sql"></a><h3>2.iii. SQL/SQL Layout</h3>
<h4>Common SQL Guidelines: </h4>
<p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (8.3+), SQLite, Oracle8, ODBC (generalised if possible)).</p>
<p>All SQL commands should utilise the DataBase Abstraction Layer (DBAL)</p>
<h4>SQL code layout:</h4>
<p>SQL Statements are often unreadable without some formatting, since they tend to be big at times. Though the formatting of sql statements adds a lot to the readability of code. SQL statements should be formatted in the following way, basically writing keywords: </p>
<divclass="codebox"><pre>
$sql = 'SELECT *
<-one tab->FROM ' . SOME_TABLE . '
<-one tab->WHERE a = 1
<-two tabs->AND (b = 2
<-three tabs->OR b = 3)
<-one tab->ORDER BY b';
</pre></div>
<p>Here the example with the tabs applied:</p>
<divclass="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . '
WHERE a = 1
AND (b = 2
OR b = 3)
ORDER BY b';
</pre></div>
<h4>SQL Quotes: </h4>
<p>Use double quotes where applicable. (The variables in these examples are typecasted to integers beforehand.) Examples: </p>
<pclass="bad">// These are wrong.</p>
<divclass="codebox"><pre>
"UPDATE " . SOME_TABLE . " SET something = something_else WHERE a = $b";
'UPDATE ' . SOME_TABLE . ' SET something = ' . $user_id . ' WHERE a = ' . $something;
</pre></div>
<pclass="good">// These are right. </p>
<divclass="codebox"><pre>
'UPDATE ' . SOME_TABLE . " SET something = something_else WHERE a = $b";
'UPDATE ' . SOME_TABLE . " SET something = $user_id WHERE a = $something";
</pre></div>
<p>In other words use single quotes where no variable substitution is required or where the variable involved shouldn't appear within double quotes. Otherwise use double quotes.</p>
<h4>Avoid DB specific SQL: </h4>
<p>The "not equals operator", as defined by the SQL:2003 standard, is "<>"</p>
<pclass="bad">// This is wrong.</p>
<divclass="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . '
WHERE a != 2';
</pre></div>
<pclass="good">// This is right. </p>
<divclass="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . '
WHERE a <> 2';
</pre></div>
<h4>Common DBAL methods: </h4>
<h4>sql_escape():</h4>
<p>Always use <code>$db->sql_escape()</code> if you need to check for a string within an SQL statement (even if you are sure the variable cannot contain single quotes - never trust your input), for example:</p>
<divclass="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . "
WHERE username = '" . $db->sql_escape($username) . "'";
</pre></div>
<h4>sql_query_limit():</h4>
<p>We do not add limit statements to the sql query, but instead use <code>$db->sql_query_limit()</code>. You basically pass the query, the total number of lines to retrieve and the offset.</p>
<p><strong>Note: </strong> Since Oracle handles limits differently and because of how we implemented this handling you need to take special care if you use <code>sql_query_limit</code> with an sql query retrieving data from more than one table.</p>
<p>Make sure when using something like "SELECT x.*, y.jars" that there is not a column named jars in x; make sure that there is no overlap between an implicit column and the explicit columns.</p>
<h4>sql_build_array():</h4>
<p>If you need to UPDATE or INSERT data, make use of the <code>$db->sql_build_array()</code> function. This function already escapes strings and checks other types, so there is no need to do this here. The data to be inserted should go into an array - <code>$sql_ary</code> - or directly within the statement if one or two variables needs to be inserted/updated. An example of an insert statement would be:</p>
<p>To complete the example, this is how an update statement would look like:</p>
<divclass="codebox"><pre>
$sql_ary = array(
'somedata' => $my_string,
'otherdata' => $an_int,
'moredata' => $another_int,
);
$sql = 'UPDATE ' . SOME_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $user_id;
$db->sql_query($sql);
</pre></div>
<p>The <code>$db->sql_build_array()</code> function supports the following modes: <code>INSERT</code> (example above), <code>INSERT_SELECT</code> (building query for <code>INSERT INTO table (...) SELECT value, column ...</code> statements), <code>UPDATE</code> (example above) and <code>SELECT</code> (for building WHERE statement [AND logic]).</p>
<h4>sql_multi_insert():</h4>
<p>If you want to insert multiple statements at once, please use the separate <code>sql_multi_insert()</code> method. An example:</p>
<divclass="codebox"><pre>
$sql_ary = array();
$sql_ary[] = array(
'somedata' => $my_string_1,
'otherdata' => $an_int_1,
'moredata' => $another_int_1,
);
$sql_ary[] = array(
'somedata' => $my_string_2,
'otherdata' => $an_int_2,
'moredata' => $another_int_2,
);
$db->sql_multi_insert(SOME_TABLE, $sql_ary);
</pre></div>
<h4>sql_in_set():</h4>
<p>The <code>$db->sql_in_set()</code> function should be used for building <code>IN ()</code> and <code>NOT IN ()</code> constructs. Since (specifically) MySQL tend to be faster if for one value to be compared the <code>=</code> and <code><></code> operator is used, we let the DBAL decide what to do. A typical example of doing a positive match against a number of values would be:</p>
<divclass="codebox"><pre>
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
$db->sql_query($sql);
</pre></div>
<p>Based on the number of values in $forum_ids, the query can look differently.</p>
<pclass="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
<divclass="codebox"><pre>
SELECT FROM phpbb_forums WHERE forum_id IN (1, 2, 3)
</pre></div>
<pclass="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
<divclass="codebox"><pre>
SELECT FROM phpbb_forums WHERE forum_id = 1
</pre></div>
<p>Of course the same is possible for doing a negative match against a number of values:</p>
<divclass="codebox"><pre>
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids, <strong>true</strong>);
$db->sql_query($sql);
</pre></div>
<p>Based on the number of values in $forum_ids, the query can look differently here too.</p>
<pclass="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
<divclass="codebox"><pre>
SELECT FROM phpbb_forums WHERE forum_id <strong>NOT</strong> IN (1, 2, 3)
</pre></div>
<pclass="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
<divclass="codebox"><pre>
SELECT FROM phpbb_forums WHERE forum_id <strong><></strong> 1
</pre></div>
<p>If the given array is empty, an error will be produced.</p>
<h4>sql_build_query():</h4>
<p>The <code>$db->sql_build_query()</code> function is responsible for building sql statements for SELECT and SELECT DISTINCT queries if you need to JOIN on more than one table or retrieve data from more than one table while doing a JOIN. This needs to be used to make sure the resulting statement is working on all supported db's. Instead of explaining every possible combination, I will give a short example:</p>
<p>The possible first parameter for sql_build_query() is SELECT or SELECT_DISTINCT. As you can see, the logic is pretty self-explaining. For the LEFT_JOIN key, just add another array if you want to join on to tables for example. The added benefit of using this construct is that you are able to easily build the query statement based on conditions - for example the above LEFT_JOIN is only necessary if server side topic tracking is enabled; a slight adjustement would be:</p>
<p>Always try to optimize your loops if operations are going on at the comparing part, since this part is executed every time the loop is parsed through. For assignments a descriptive name should be chosen. Example:</p>
<pclass="bad">// On every iteration the sizeof function is called</p>