2015-02-02, 03:19 PM
I noticed that when a user with no stored attachments opens a new thread or a new reply gets the following at the bottom of his screen:
[attachment=33675]
I have located the source of N/A in this text, and why it is not 0. It appears that the query and statement below that at line 976 of newthread.php and line 1180 of newreply.php:
results in a variable $usage['ausage'] equal to NULL. This variable is passed to the function get_friendly_size at line 991 of newthread.php and line 1197 of newreply.php.
I have checked it, and the problem can be solved by changing this statement in both modules to:
by which we get at the bottom of the newthread and newreply pages:
[attachment=33676]
But I think it is more a matter of principle to look more closely at the function get_friendly_size in /inc/functions.php. This function checks at line 3654 whether the passed argument is numeric:
where $size is the passed argument. Apparently a NULL variable is not considered to be a numerical value or a numerical string, and function is_numeric returns false for an argument with value NULL. I think this is wrong in principle, because PHP considers NULL equal to zero when compared with an integer. That's why my proposal is to change line 3654 of /inc/functions.php into:
I tried it and this yields the same result as changing newthread.php and newreply.php.
I realize that this is a very very small issue, so when the opinion is that this kind of things is not worth looking at, please let me know. I still have a few .
EDIT
I know that comparing NULL with negative integers goes wrong, but that is not relavant function get_friendly_size.
[attachment=33675]
I have located the source of N/A in this text, and why it is not 0. It appears that the query and statement below that at line 976 of newthread.php and line 1180 of newreply.php:
$query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
$usage = $db->fetch_array($query);
results in a variable $usage['ausage'] equal to NULL. This variable is passed to the function get_friendly_size at line 991 of newthread.php and line 1197 of newreply.php.
$friendlyusage = get_friendly_size($usage['ausage']);
I have checked it, and the problem can be solved by changing this statement in both modules to:
$friendlyusage = get_friendly_size((int)$usage['ausage']);
by which we get at the bottom of the newthread and newreply pages:
[attachment=33676]
But I think it is more a matter of principle to look more closely at the function get_friendly_size in /inc/functions.php. This function checks at line 3654 whether the passed argument is numeric:
if(!is_numeric($size))
{
return $lang->na;
}
where $size is the passed argument. Apparently a NULL variable is not considered to be a numerical value or a numerical string, and function is_numeric returns false for an argument with value NULL. I think this is wrong in principle, because PHP considers NULL equal to zero when compared with an integer. That's why my proposal is to change line 3654 of /inc/functions.php into:
if(!is_numeric($size) && !is_null($size))
I tried it and this yields the same result as changing newthread.php and newreply.php.
I realize that this is a very very small issue, so when the opinion is that this kind of things is not worth looking at, please let me know. I still have a few .
EDIT
I know that comparing NULL with negative integers goes wrong, but that is not relavant function get_friendly_size.