1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/14972] Fix sizeof calls

As of PHP 7.2, only arrays and objects implementing the Countable interface
should be passed as a count() or sizeof() parameter.
See https://github.com/php/php-src/blob/php-7.2.0alpha2/UPGRADING#L197-L198
Also, sizeof() seems to be sheduled for deprecation, see
https://wiki.php.net/rfc/deprecations_php_7_2#suggested_deprecations

PHPBB3-14972
This commit is contained in:
rxu
2017-01-09 00:23:08 +07:00
parent 07c6e821d5
commit 055a5f8040
5 changed files with 113 additions and 116 deletions

View File

@@ -537,7 +537,9 @@ abstract class driver implements driver_interface
*/
function sql_in_set($field, $array, $negate = false, $allow_empty_set = false)
{
if (!sizeof($array))
$array = (array) $array;
if (!count($array))
{
if (!$allow_empty_set)
{
@@ -559,12 +561,7 @@ abstract class driver implements driver_interface
}
}
if (!is_array($array))
{
$array = array($array);
}
if (sizeof($array) == 1)
if (count($array) == 1)
{
@reset($array);
$var = current($array);
@@ -632,7 +629,7 @@ abstract class driver implements driver_interface
*/
function sql_multi_insert($table, $sql_ary)
{
if (!sizeof($sql_ary))
if (!count($sql_ary))
{
return false;
}
@@ -738,7 +735,7 @@ abstract class driver implements driver_interface
// We run the following code to determine if we need to re-order the table array. ;)
// The reason for this is that for multi-aliased tables (two equal tables) in the FROM statement the last table need to match the first comparison.
// DBMS who rely on this: Oracle, PostgreSQL and MSSQL. For all other DBMS it makes absolutely no difference in which order the table is.
if (!empty($array['LEFT_JOIN']) && sizeof($array['FROM']) > 1 && $used_multi_alias !== false)
if (!empty($array['LEFT_JOIN']) && count($array['FROM']) > 1 && $used_multi_alias !== false)
{
// Take first LEFT JOIN
$join = current($array['LEFT_JOIN']);
@@ -848,7 +845,7 @@ abstract class driver implements driver_interface
default:
switch (sizeof($condition))
switch (count($condition))
{
case 3:
@@ -1138,7 +1135,7 @@ abstract class driver implements driver_interface
$html_table = func_get_arg(2);
$row = func_get_arg(3);
if (!$html_table && sizeof($row))
if (!$html_table && count($row))
{
$html_table = true;
$this->html_hold .= '<table cellspacing="1"><tr>';

View File

@@ -99,7 +99,7 @@ class session
$root_dirs = array_diff_assoc($root_dirs, $intersection);
$page_dirs = array_diff_assoc($page_dirs, $intersection);
$page_dir = str_repeat('../', sizeof($root_dirs)) . implode('/', $page_dirs);
$page_dir = str_repeat('../', count($root_dirs)) . implode('/', $page_dirs);
if ($page_dir && substr($page_dir, -1, 1) == '/')
{
@@ -118,8 +118,8 @@ class session
// The script path from the webroot to the phpBB root (for example: /phpBB3/)
$script_dirs = explode('/', $script_path);
array_splice($script_dirs, -sizeof($page_dirs));
$root_script_path = implode('/', $script_dirs) . (sizeof($root_dirs) ? '/' . implode('/', $root_dirs) : '');
array_splice($script_dirs, -count($page_dirs));
$root_script_path = implode('/', $script_dirs) . (count($root_dirs) ? '/' . implode('/', $root_dirs) : '');
// We are on the base level (phpBB root == webroot), lets adjust the variables a bit...
if (!$root_script_path)
@@ -575,12 +575,12 @@ class session
$provider = $provider_collection->get_provider();
$this->data = $provider->autologin();
if ($user_id !== false && sizeof($this->data) && $this->data['user_id'] != $user_id)
if ($user_id !== false && isset($this->data['user_id']) && $this->data['user_id'] != $user_id)
{
$this->data = array();
}
if (sizeof($this->data))
if (isset($this->data['user_id']))
{
$this->cookie_data['k'] = '';
$this->cookie_data['u'] = $this->data['user_id'];
@@ -588,7 +588,7 @@ class session
// If we're presented with an autologin key we'll join against it.
// Else if we've been passed a user_id we'll grab data based on that
if (isset($this->cookie_data['k']) && $this->cookie_data['k'] && $this->cookie_data['u'] && !sizeof($this->data))
if (isset($this->cookie_data['k']) && $this->cookie_data['k'] && $this->cookie_data['u'] && empty($this->data))
{
$sql = 'SELECT u.*
FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k
@@ -608,7 +608,7 @@ class session
$db->sql_freeresult($result);
}
if ($user_id !== false && !sizeof($this->data))
if ($user_id !== false && empty($this->data))
{
$this->cookie_data['k'] = '';
$this->cookie_data['u'] = $user_id;
@@ -636,7 +636,7 @@ class session
// User does not exist
// User is inactive
// User is bot
if (!sizeof($this->data) || !is_array($this->data))
if (!is_array($this->data) || !count($this->data))
{
$this->cookie_data['k'] = '';
$this->cookie_data['u'] = ($bot) ? $bot : ANONYMOUS;
@@ -1013,7 +1013,7 @@ class session
}
$db->sql_freeresult($result);
if (sizeof($del_user_id))
if (count($del_user_id))
{
// Delete expired sessions
$sql = 'DELETE FROM ' . SESSIONS_TABLE . '
@@ -1147,7 +1147,7 @@ class session
$where_sql[] = $_sql;
}
$sql .= (sizeof($where_sql)) ? implode(' AND ', $where_sql) : '';
$sql .= (count($where_sql)) ? implode(' AND ', $where_sql) : '';
$result = $db->sql_query($sql, $cache_ttl);
$ban_triggered_by = 'user';