SimplePortal
Development => Bugs => Topic started by: KathyL on July 08, 2017, 06:27:55 AM
-
Since the implementation of PHP 7.1 warnings are issued about invalid strings in arithmetic (https://wiki.php.net/rfc/invalid_strings_in_arithmetic).
For SMF 2.0.14/Simple Portal 2.3.6/PHP 7.1 this has resulted in 'A non well formed numeric value encountered' error messages on my forums whenever changes to blocks are saved because of the presence of non-numeric characters (eg, '%', 'px').
The workaround I implemented in ./Sources/PortalAdminBlocks.php is as follows (ie, insert '(float)' before each width value used in the calculations to return only the numeric value):
Find
if (strpos($context['widths'][1], '%') !== false)
$context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%';
elseif (strpos($context['widths'][1], 'px') !== false)
$context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px';
if (strpos($context['widths'][1], '%') !== false)
{
$context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%';
$context['widths'][5] = $context['widths'][6] = '100%';
}
elseif (strpos($context['widths'][1], 'px') !== false)
{
$context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px';
$context['widths'][5] = $context['widths'][6] = '960px';
}
Replace with:
if (strpos($context['widths'][1], '%') !== false)
$context['widths'][2] = $context['widths'][3] = 100 - ((float)$context['widths'][1] + (float)$context['widths'][4]) . '%';
elseif (strpos($context['widths'][1], 'px') !== false)
$context['widths'][2] = $context['widths'][3] = 960 - ((float)$context['widths'][1] + (float)$context['widths'][4]) . 'px';
if (strpos($context['widths'][1], '%') !== false)
{
$context['widths'][2] = $context['widths'][3] = 100 - ((float)$context['widths'][1] + (float)$context['widths'][4]) . '%';
$context['widths'][5] = $context['widths'][6] = '100%';
}
elseif (strpos($context['widths'][1], 'px') !== false)
{
$context['widths'][2] = $context['widths'][3] = 960 - ((float)$context['widths'][1] + (float)$context['widths'][4]) . 'px';
$context['widths'][5] = $context['widths'][6] = '960px';
}
-
Thanks for the report although intval may be for suitable than float.
-
Thanks for the report although intval may be for suitable than float.
Thanks for the suggestion - I'll update my code.
Update: I tried 'intval' but it generated "syntax error, unexpected '$context' (T_VARIABLE)" errors - 'int' seems to be working though.
-
intval is a function
int is a type
Both are equivalent in the outcome, but you use them differently:
$something = intval($something);
$something = (int) $something;
-
For a better understanding, you can use php.net for a reference:
http://php.net/manual/en/function.intval.php