From f8fbe3793680af1dae2db2829cfc84068831c52f Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 28 Jun 2017 00:58:03 +0700 Subject: [ticket/14972] replace all occurrences of sizeof() with the count() PHPBB3-14972 --- phpBB/docs/coding-guidelines.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/docs/coding-guidelines.html') 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;
if (isset($forum) && $forum == 5)
-

The empty() 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 isset($array) && sizeof($array) > 0 - this can be written in a shorter way as !empty($array).

+

The empty() 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 isset($array) && count($array) > 0 - this can be written in a shorter way as !empty($array).

Switch statements:

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:

@@ -994,9 +994,9 @@ $sql = $db->sql_build_query('SELECT', $sql_array);

Operations in loop definition:

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:

-

// On every iteration the sizeof function is called

+

// On every iteration the count function is called

-for ($i = 0; $i < sizeof($post_data); $i++)
+for ($i = 0; $i < count($post_data); $i++)
 {
 	do_something();
 }
@@ -1004,7 +1004,7 @@ for ($i = 0; $i < sizeof($post_data); $i++)

// You are able to assign the (not changing) result within the loop itself

-for ($i = 0, $size = sizeof($post_data); $i < $size; $i++)
+for ($i = 0, $size = count($post_data); $i < $size; $i++)
 {
 	do_something();
 }
-- cgit v1.2.1