iopietro / Travianz-Legacy

Join our Discord Server: https://discordapp.com/invite/9fbJKP9 | New repo: https://github.com/iopietro/Travianz
GNU General Public License v3.0
160 stars 94 forks source link

Some warnings with PHP 7.2 in statistics #554

Closed velhbxtyrj closed 5 years ago

velhbxtyrj commented 5 years ago

default

This warning is displayed if there are no players in the statistics at all.

Warning: count(): Parameter must be an array or an object that implements Countable in C:\OSPanel\domains\TravianZ-master\Templates\Ranking\ranksearch.tpl on line 21

If this is the right decision then can implement it:

The selected part is bold:

else if($start == 1 && $start+20 < count($ranking)) {

Replace with the selected part in bold

else if($start == 1 && $start+20 < count([$ranking])) {

1

iopietro commented 5 years ago

In general it's better "empty($ranking)" or "$ranking == false" to check if an array is empty or not.

So, it should be something like this:

if(empty($ranking)) echo "..."; else if(...) etc.

(I'm not at the PC right now, I can't format the code properly)

iopietro commented 5 years ago

Ok, this is the full code:

if(!empty($ranking)){
    if($start != 1 && $start + 20 < count($ranking)) {
        echo "<a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start - 20)."\">&laquo; back</a> | <a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start + 20)."\">forward &raquo;</a>";
    }
    else if($start == 1 && $start + 20 < count($ranking)) {
        echo "&laquo; back | <a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start + 20)."\">forward &raquo;</a>";
    }else if($start != 1 && $start - 20 < count($ranking)) {
        echo "<a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start - 20)."\">&laquo; back</a> | forward &raquo;";
    }
    else echo "&laquo; back | forward &raquo;";
}
else echo "&laquo; back | forward &raquo;";
velhbxtyrj commented 5 years ago

And unless it is not necessary in the second if to remove here this line?

else echo "&laquo; back | forward &raquo;";

This line is moved to the first if

iopietro commented 5 years ago

It could be reduced in a single if, with something like this:

if(empty($ranking) || count($ranking) <= 20){
    echo "&laquo; back | forward &raquo;";
}else if($start != 1 && $start + 20 < count($ranking)) {
    echo "<a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start - 20)."\">&laquo; back</a> | <a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start + 20)."\">forward &raquo;</a>";
}else if($start == 1 && $start + 20 < count($ranking)) {
    echo "&laquo; back | <a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start + 20)."\">forward &raquo;</a>";
}else if($start != 1 && $start - 20 < count($ranking)) {
    echo "<a href=\"statistiken.php?id=".$_GET['id']."&amp;rank=".($start - 20)."\">&laquo; back</a> | forward &raquo;";
}
velhbxtyrj commented 5 years ago

It will be better if you correct this warning yourself :)

iopietro commented 5 years ago

It turned out that it was a bigger problem than I expected, caused by calling with the same name 2 variables in the same scope ($ranking).