getminera / minera

Minera is a web interface to monitor and manage mining devices
http://getminera.com
Other
374 stars 156 forks source link

count() reports error on non-countable objects in php7.2 #243

Closed PSLLSP closed 3 years ago

PSLLSP commented 5 years ago

Describe the bug php 7.2 changes behavior of count() function; it is not a bug but the feature! When count() was called with NULL or scalar in the past, it returned 0 or 1. In php-7.2, it throws an exception!

To Reproduce Several places use count() in "dangerous way", example is minera/application/views/frontpage.php, line 17 ($netMiners could be NULL):

<?php if (count($netMiners) > 0) : ?>

A PHP Error was encountered
Severity: Warning

Message: count(): Parameter must be an array or an object that implements Countable

Filename: views/frontpage.php

Line Number: 17

Solution is to check type of value with gettype() and use count only on array or initialize values with empty arrays...

I installed Minera manually to Ubuntu 18.04.4 with php 7.2 and I see this problem...

BTW, instructions for manual installation doesn't work, they are full of incorrect/outdated instructions, and several steps are missing...

PSLLSP commented 5 years ago

There is a bug in file minera/application/controllers/app.php, one condition is wrong:

class App extends CI_Controller {
....
-               if (count($boxStatuses > 0)) {
+               if (count($boxStatuses) > 0) {
michelem09 commented 5 years ago

Hey thanks, if you can do a pull request I will review it