Error Log is filed with numeric value errors

Started by Demidrin, June 13, 2017, 01:57:59 AM

Previous topic - Next topic

Demidrin

Hi everyone,

since the 2.0.14 update I have this kind of error (where UUU is a random user ID):


... index.php?action=profile;area=statistics;u=UUU
Apply Filter: Only show the errors with the same message
8: A non well formed numeric value encountered
Apply Filter: Only show the errors from this file
File: /.../Themes/default/GenericMenu.template.php (statPanel sub template - eval?)
Line: 1105


The stat page seems to load without display errors (I don't see anything not working).

Can you tell me, where I can find this in the code?
I want to have a look at it and maybe disable the line.

BR

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Why? The issue is Profile.template.php, line 1105...

Demidrin

Quote from: Kindred on June 13, 2017, 06:20:50 AM
please turn off eval? (server settings)
Why? Does this forum doesn't support this? (I'm curious.)

Quote from: Arantor on June 13, 2017, 07:13:13 AM
Why? The issue is Profile.template.php, line 1105...
Thank you, I always looked into GenericMenu.template.php and wondered where the hell the line numbers are... :)

Biology Forums

Is the problem fixed? You must have installed something accidentally that's mucking things up

Arantor

Eval obfuscates where the real error is, but it's usually not hard to see where the real error can be found.

Biology Forums

In addition, depending on the permissions given to you by your host, you could also look for core errors in the Apache error log, which pinpoint the exact errors.

Demidrin

Quote from: Stylus on June 13, 2017, 10:52:42 AM
Is the problem fixed? You must have installed something accidentally that's mucking things up
Not yet, but I'm looking into it as soon as I have some time.

Quote from: Arantor on June 13, 2017, 10:56:55 AM
Eval obfuscates where the real error is, but it's usually not hard to see where the real error can be found.
I would like to understand the error/warning first, before I turn something off.

Quote from: Stylus on June 13, 2017, 10:57:02 AM
In addition, depending on the permissions given to you by your host, you could also look for core errors in the Apache error log, which pinpoint the exact errors.
It isn't my web space and apparently the error logs aren't activated.
If I can't figure it out, I'll ask for them. But so fare the code looks promising.

For the protocol: this is the line:
<div class="profile_pie" style="background-position: -', ((int) ($activity['percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '">

I'll write a final note, as soon as I figured out the problem.

Arantor

What Kindred suggested won't fix anything at all. You saw yourself that the line being referred to in the error log was not correct, this is because the eval process causes it to be misreported. (No, this isn't a bug, it's the result of the design of how eval works. Eval is a safety net so that if a template is broken, SMF can catch it and issue a safe error page)

Does the user have posts? Do the little pie charts look logical for the user?

Demidrin

Quote from: Arantor on June 13, 2017, 11:09:27 AM
What Kindred suggested won't fix anything at all. You saw yourself that the line being referred to in the error log was not correct, this is because the eval process causes it to be misreported. (No, this isn't a bug, it's the result of the design of how eval works. Eval is a safety net so that if a template is broken, SMF can catch it and issue a safe error page)
Ah, good to know.

Quote from: Arantor on June 13, 2017, 11:09:27 AM
Does the user have posts? Do the little pie charts look logical for the user?
The problem exists for all users (for all I tested at least).
The pie chart is off I think: For the example below: Only one board shown with the percentage of 0,11%.

And here are some sample value:

$activity['percent'] = 0,11
$activity['posts'] = 1
$activity['total_posts'] = 899
$activity['posts_percent'] = 0.1112
$txt['statPanel_topBoards_posts'] = %1$d Beiträge des Boards %2$d Beiträge (%3$01.2f%%)


As far as I know, the forum is pretty vanilla. Only in some boards the post counting is disabled via settings.

Arantor

Ok, it's confused by the fact that your activity value is 0,11 which the code cannot understand as being a number. PHP only understands . as the decimal point.

I wonder how it broke.

Demidrin

Quote from: Arantor on June 13, 2017, 11:28:29 AM
I wonder how it broke.
Maybe a locale thing. Once it used the comma and the other time the point. Ours is a German forum, so comma is the German way of writing double values.

Shambles

@Demidrin, have you recently upped your version of PHP?

I noticed a few of these errors appearing, once I'd raised my PHP level to above 5.6 (I'm on 7.1.5)

I'm wondering of there's been a tightening up of numeracy checks within PHP at the higher versions.

Demidrin

Quote from: Shambles on June 13, 2017, 11:45:01 AM
@Demidrin, have you recently upped your version of PHP?

I noticed a few of these errors appearing, once I'd raised my PHP level to above 5.6 (I'm on 7.1.5)

I'm wondering of there's been a tightening up of numeracy checks within PHP at the higher versions.
Yes, we switch to PHP 7.1 too. I was just searching for this kind of errors in combination with PHP 7. :)

P.S.: I forgot to mention: I went back to PHP 5.6 and the error message is gone, but not the strange calculation of the pie chart.

Arantor

Maybe but that shouldn't be affecting internal calculations like that.

PHP is definitely more picky now, too, but this sounds like it's always been at least partially broken.

Demidrin

Quote from: Arantor on June 13, 2017, 12:21:10 PM
Maybe but that shouldn't be affecting internal calculations like that.

PHP is definitely more picky now, too, but this sounds like it's always been at least partially broken.
Indeed, this is only the explanation why there are only now error messages.

I'll look into the root cause later, when I have time.

Demidrin

Alright, it seems at least at my template there is a bug for default number format using commas in decimal numbers?

The current situation (line numbers may differ):
Profile.template.php (line 1099)
// Draw a bar for every board.
foreach ($context['board_activity'] as $activity)
{
echo '
<dt>', $activity['link'], '</dt>
<dd>
<div class="profile_pie" style="background-position: -', ((int) ($activity['percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '">
', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '
</div>
<span>', $activity['percent'], '%</span>
</dd>';
}


And the calculation:
Profile-View.php (line 780):
$context['board_activity'][$row['id_board']] = array(
'id' => $row['id_board'],
'posts' => $row['message_count'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
'percent' => comma_format((float) $row['percentage'], 2),
'posts_percent' => (float) $row['percentage'],
'total_posts' => $row['num_posts'],
);


Value percent is with formatting (e.g. 38,20) and value posts_percent is without (e.g. 38.199).
As you can see above, the formatted value percent is used once for the template calculation.




I fixed this template part like this (using now the correct value for the calculation part):
Profile.template.php (line 1099)
// Draw a bar for every board.
foreach ($context['board_activity'] as $activity)
{
echo '
<dt>', $activity['link'], '</dt>
<dd>
<div class="profile_pie" style="background-position: -', ((int) ($activity['posts_percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '">
', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '
</div>
<span>', $activity['percent'], '%</span>
</dd>';
}

That sprintf($txt['statPanel_topBoards_posts'],...) from my German translation still prints a point instead of a comma, but I don't care.

Maybe somebody can check if this is a general problem in the default template?

BR

Arantor

It shouldn't need to change the sprintf part, just the line before.

But it is a problem with the default theme by the looks of it.

FishingManMatt

Hi!

Old topic, but I can confirm - after switching to PHP 7.1 I started getting the same log errors.
Just changed the code as Demidrin suggested and log errors are gone.

Advertisement: