diff options
Diffstat (limited to 'phpBB/docs/coding-guidelines.html')
-rw-r--r-- | phpBB/docs/coding-guidelines.html | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index d90f4d4d32..569ffe680c 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -627,7 +627,7 @@ $min = ($i < $j) ? $i : $j;</pre> <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> + <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) && count($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> @@ -994,9 +994,9 @@ $sql = $db->sql_build_query('SELECT', $sql_array);</pre> <h4>Operations in loop definition: </h4> <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> - <p class="bad">// On every iteration the sizeof function is called</p> + <p class="bad">// On every iteration the count function is called</p> <div class="codebox"><pre> -for ($i = 0; $i < sizeof($post_data); $i++) +for ($i = 0; $i < count($post_data); $i++) { do_something(); }</pre> @@ -1004,7 +1004,7 @@ for ($i = 0; $i < sizeof($post_data); $i++) <p class="good">// You are able to assign the (not changing) result within the loop itself</p> <div class="codebox"><pre> -for ($i = 0, $size = sizeof($post_data); $i < $size; $i++) +for ($i = 0, $size = count($post_data); $i < $size; $i++) { do_something(); }</pre> |