Skip to content

Commit

Permalink
[ticket/14972] replace all occurrences of sizeof() with the count()
Browse files Browse the repository at this point in the history
PHPBB3-14972
  • Loading branch information
rxu committed Jul 17, 2017
1 parent 67a65e3 commit 797234e
Show file tree
Hide file tree
Showing 165 changed files with 986 additions and 986 deletions.
4 changes: 2 additions & 2 deletions build/build_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function build_package($versions, $verbose = false)
$this->verbose = $verbose;

// Get last two entries
$_latest = $this->versions[sizeof($this->versions) - 1];
$_before = $this->versions[sizeof($this->versions) - 2];
$_latest = $this->versions[count($this->versions) - 1];
$_before = $this->versions[count($this->versions) - 2];

$this->locations = array(
'new_version' => dirname(dirname(__FILE__)) . '/phpBB/',
Expand Down
16 changes: 8 additions & 8 deletions build/package.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

// Go trough all versions making a diff if we even have old versions
// For phpBB 3.0.x we might choose a different update method, rendering the things below useless...
if (sizeof($package->old_packages))
if (count($package->old_packages))
{
chdir($package->locations['old_versions']);

Expand Down Expand Up @@ -76,7 +76,7 @@
// Create Directories along the way?
$file = explode('/', $file);
// Remove filename portion
$file[sizeof($file)-1] = '';
$file[count($file)-1] = '';

chdir($dest_filename_dir);
foreach ($file as $entry)
Expand Down Expand Up @@ -169,7 +169,7 @@
// Create Directories along the way?
$file = explode('/', $file);
// Remove filename portion
$file[sizeof($file)-1] = '';
$file[count($file)-1] = '';

chdir($dest_filename_dir . '/install/update/old');
foreach ($file as $entry)
Expand Down Expand Up @@ -214,7 +214,7 @@
// Create Directories along the way?
$file = explode('/', $file);
// Remove filename portion
$file[sizeof($file)-1] = '';
$file[count($file)-1] = '';

chdir($dest_filename_dir . '/install/update/new');
foreach ($file as $entry)
Expand Down Expand Up @@ -321,7 +321,7 @@
\'version\' => array(\'from\' => \'' . str_replace('_to_', '', $package->old_packages[$_package_name]) . '\', \'to\' => \'' . $package->get('new_version_number') . '\'),
';

if (sizeof($file_contents['all']))
if (count($file_contents['all']))
{
$index_contents .= "\t'files' => array(\n\t\t'" . implode("',\n\t\t'", $file_contents['all']) . "',\n\t),\n";
}
Expand All @@ -330,7 +330,7 @@
$index_contents .= "\t'files' => array(),\n";
}

if (sizeof($file_contents['binary']))
if (count($file_contents['binary']))
{
$index_contents .= "\t'binary' => array(\n\t\t'" . implode("',\n\t\t'", $file_contents['binary']) . "',\n\t),\n";
}
Expand All @@ -339,7 +339,7 @@
$index_contents .= "\t'binary' => array(),\n";
}

if (sizeof($file_contents['deleted']))
if (count($file_contents['deleted']))
{
$index_contents .= "\t'deleted' => array(\n\t\t'" . implode("',\n\t\t'", $file_contents['deleted']) . "',\n\t),\n";
}
Expand Down Expand Up @@ -380,7 +380,7 @@
'zip' => 'zip -r'
);

if (sizeof($package->old_packages))
if (count($package->old_packages))
{
// Build Patch Files
chdir($package->get('patch_directory'));
Expand Down
4 changes: 2 additions & 2 deletions phpBB/develop/add_permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
}
$db->sql_freeresult($result);

if (sizeof($remove_auth_options))
if (count($remove_auth_options))
{
$db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id IN (' . implode(', ', $remove_auth_options) . ')');
$db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id IN (' . implode(', ', $remove_auth_options) . ')');
Expand All @@ -199,7 +199,7 @@
foreach ($prefixes as $prefix)
{
$var = $prefix . 'permissions';
if (sizeof(${$var}))
if (count(${$var}))
{
foreach (${$var} as $auth_option => $l_ary)
{
Expand Down
2 changes: 1 addition & 1 deletion phpBB/develop/check_flash_bbcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function check_table_flash_bbcodes($table_name, $id_field, $content_field, $uid_

$ids = get_table_flash_bbcode_pkids($table_name, $id_field, $content_field, $uid_field, $bitfield_field);

$size = sizeof($ids);
$size = count($ids);
if ($size)
{
echo "Found $size potentially dangerous flash bbcodes.\n";
Expand Down
4 changes: 2 additions & 2 deletions phpBB/develop/create_variable_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@

$html_data .= '<b>' . $lang_var . '</b><ul>';

if (sizeof($filenames) != 1)
if (count($filenames) != 1)
{
fwrite($common_fp, (($entry['common']) ? ",\n" : '') . "\t'$var' => '" . $lang[$var] . "'");
$entry['common'] = true;
}
else if (sizeof($filenames) == 1)
else if (count($filenames) == 1)
{
// Merge logical - hardcoded
$fname = (preg_match('#^(' . implode('|', $merge) . ')#', $filenames[0], $match)) ? $match[0] . '.php' : str_replace($ext, 'php', $filenames[0]);
Expand Down
2 changes: 1 addition & 1 deletion phpBB/develop/search_fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
$rowset = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);

$post_rows = sizeof($rowset);
$post_rows = count($rowset);

if( $post_rows )
{
Expand Down
8 changes: 4 additions & 4 deletions phpBB/docs/coding-guidelines.html
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ <h4>Don't use uninitialized variables.</h4>
<pre>if (isset($forum) &amp;&amp; $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) &amp;&amp; sizeof($array) &gt; 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) &amp;&amp; count($array) &gt; 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>
Expand Down Expand Up @@ -994,17 +994,17 @@ <h4>sql_build_query():</h4>
<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 &lt; sizeof($post_data); $i++)
for ($i = 0; $i &lt; count($post_data); $i++)
{
do_something();
}</pre>
</div>

<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 &lt; $size; $i++)
for ($i = 0, $size = count($post_data); $i &lt; $size; $i++)
{
do_something();
}</pre>
Expand Down
Loading

0 comments on commit 797234e

Please sign in to comment.