Skip to main content
Topic: [1.0.10] Total karma mode broken on PHP 7.0/7.1 (Read 3279 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[1.0.10] Total karma mode broken on PHP 7.0/7.1

On PHP 7.1 with enabled total karma user profile in post show only negative karma points.

PHP 7.0 has the same issue but error log is empty. In both cases Karma label set in settings is not displayed in topic view.
Karma count and label on action?profile is correct.

With enabled karma positive/negative label is visible in topic view, so maybe it's only related to Total Karma mode.

Code: [Select]
This version: ElkArte 1.0.10 (more detailed)
Current version: 1.0.10
GD version: bundled (2.1.0 compatible)
MySQL version: 10.1.21-MariaDB-cll-lve
Zend OPcache: 7.1.3
PHP: 7.1.3 (litespeed) (more detailed)
Server version: LiteSpeed

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #1

I just installed 7.1 on one of my sites so will be able to check soon

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #2

maybe it was even before 1.0.10, but only yesterday I moved my sites to new host where I can choose PHP versions

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #3

Well this was not what I thought it would be. 

I thought this would be some cast problem, where we passing a string or null value and expected PHP to auto cast when the "math" was done.  But after ensuring that ints were being passed to the template the error persisted.  In doing some testing, its actually a template error, at least in php 7.x

In GenericMessages.template.php
Code: (find) [Select]
									<li class="listlevel2 karma">' . $modSettings['karmaLabel'] . ' ' . $message['member']['karma']['good'] - $message['member']['karma']['bad'];

Code: (replace) [Select]
									<li class="listlevel2 karma">' . $modSettings['karmaLabel'] . ' ' . ($message['member']['karma']['good'] - $message['member']['karma']['bad']);
Wrapping the match in ()'s seems to fix the problem.  Looks like php7 has done some optimization on echo concatenation, as such by the time it gets to the minus sign, its using the entire left side which is a concatenated string, so it attempts to eval "Karma 2 - 1" or some such thing.  Anyway the ()'s should ensure the correct order of things, so give it a try.

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #4

Regardless of how PHP treats it, I think it's much clearer what's going on in the replacement. :)

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #5

seems to work good now :)

In find/replace code is a typo, so if anyone will copy/paste code it can break template, corrected replacement:
Code: (Find) [Select]
<li class="listlevel2 karma">' . $modSettings['karmaLabel'] . ' ' . $message['member']['karma']['good'] - $message['member']['karma']['bad'] . '</li>';
Code: (Replace with) [Select]
<li class="listlevel2 karma">' . $modSettings['karmaLabel'] . ' ' . ($message['member']['karma']['good'] - $message['member']['karma']['bad']) . '</li>';

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #6

 emanuele thinks we should do an str_replace. :P

Code: [Select]
									<li class="listlevel2 karma">' . str_replace('{karma_total}', ($message['member']['karma']['good'] - $message['member']['karma']['bad']), $modSettings['karmaLabel']);
Bugs creator.
Features destroyer.
Template killer.

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #7

@emanuele - also missing closing </li> :)

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #8

Quote from: emanuele –
 emanuele thinks we should do an str_replace. :P

Code: [Select]
									<li class="listlevel2 karma">' . str_replace('{karma_total}', ($message['member']['karma']['good'] - $message['member']['karma']['bad']), $modSettings['karmaLabel']);
for i18n?
LiveGallery - Simple gallery addon for ElkArte

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #9

Yep, I think it may make sense.
But it may also be overkill, who knows. xD

Is that a 1.1 bug as well?
Bugs creator.
Features destroyer.
Template killer.

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #10

sorry for the off-topic but with Likes enabled do we really need the Karma function? I have to admit I never used the Karma system
sorry for my bad english

Re: [1.0.10] Total karma mode broken on PHP 7.0/7.1

Reply #11

Karma and likes are two different things: one targets the user, one the content.
I never used it myself, but considering the amount of code involved it doesn't really make much difference to have it or not in terms of maintenance.
Bugs creator.
Features destroyer.
Template killer.