Cacti / cacti

Cacti ™
http://www.cacti.net
GNU General Public License v2.0
1.65k stars 406 forks source link

Passing glue string after array is deprecated in PHP 7.4 #3151

Closed StormTrooper closed 4 years ago

StormTrooper commented 4 years ago

Log files are filling up with ERROR PHP DEPRECATED

2019/12/18 13:13:16 - CMDPHP PHP ERROR Backtrace: (C:\cacti\apache24\htdocs\cacti\data_debug.php[138]:debug_wizard(), C:\cacti\apache24\htdocs\cacti\data_debug.php[530]:implode(), CactiErrorHandler())
2019/12/18 13:13:16 - ERROR PHP DEPRECATED: implode(): Passing glue string after array is deprecated. Swap the parameters in file: C:\cacti\apache24\htdocs\cacti\data_debug.php on line: 530
2019/12/18 13:13:16 - CMDPHP PHP ERROR Backtrace: (C:\cacti\apache24\htdocs\cacti\data_debug.php[138]:debug_wizard(), C:\cacti\apache24\htdocs\cacti\data_debug.php[530]:implode(), CactiErrorHandler())
2019/12/18 13:13:16 - ERROR PHP DEPRECATED: implode(): Passing glue string after array is deprecated. Swap the parameters in file: C:\cacti\apache24\htdocs\cacti\data_debug.php on line: 530
2019/12/18 13:13:16 - CMDPHP PHP ERROR Backtrace: (C:\cacti\apache24\htdocs\cacti\data_debug.php[138]:debug_wizard(), C:\cacti\apache24\htdocs\cacti\data_debug.php[530]:implode(), CactiErrorHandler())
2019/12/18 13:13:16 - ERROR PHP DEPRECATED: implode(): Passing glue string after array is deprecated. Swap the parameters in file: C:\cacti\apache24\htdocs\cacti\data_debug.php on line: 530
2019/12/18 13:13:16 - CMDPHP PHP ERROR Backtrace: (C:\cacti\apache24\htdocs\cacti\data_debug.php[138]:debug_wizard(), C:\cacti\apache24\htdocs\cacti\data_debug.php[530]:implode(), CactiErrorHandler())
2019/12/18 13:13:16 - ERROR PHP DEPRECATED: implode(): Passing glue string after array is deprecated. Swap the parameters in file: C:\cacti\apache24\htdocs\cacti\data_debug.php on line: 530
2019/12/18 13:13:16 - CMDPHP PHP ERROR Backtrace: (C:\cacti\apache24\htdocs\cacti\data_debug.php[138]:debug_wizard(), C:\cacti\apache24\htdocs\cacti\data_debug.php[530]:implode(), CactiErrorHandler()) 

To Reproduce Log onto dashboard, click on Logs

Server OS: Windows 7, 32 bit

Cacti: 1.2.8

Apache: Server version: Apache/2.4.41 (Win32) Server built: Aug 10 2019 12:59:56

PHP 7.4.0 (cli) (built: Nov 27 2019 10:15:52) ( ZTS Visual C++ 2017 x86 )

MySQL: Server version: 5.5.62-log MySQL Community Server (GPL)

frontierliu commented 4 years ago

data_debug.php line 530: $issue_title = implode($issues, ' < br/ >');

Because in PHP 4 and PHP 5, function implode(string $glue , array $pieces ) accept parameters in two order , so implode(array $pieces , string $glue) also works. But in PHP 7, function implode()'s parameters order is strict to implode(string $glue, array $pieces). how to resolved: data_debug.php line 530 swap the parameters: $issue_title = implode( '< br/ >', $issues);

I think bugs about PHP5 and PHP7's compatibility should be fixed in the future cacti version, for PHP7 is being actively supported while PHP5 is no longer supported.

.

netniV commented 4 years ago

This actually affects a few places:

data_debug.php:530:                   $issue_title = implode($issues, '<br/>');

lib/database.php:421:         db_echo_sql('db_fetch_row_prepared(\'' . clean_up_lines($sql) . '\', $params = (\'' . implode($params, '\', \'') . '\'), $log = ' . $log . ', $db_conn = ' . ($db_conn ? 'true' : 'false') .')' . "\n");

lib/dsdebug.php:248:                                  $c['issue'][] = __('Failed fields: ') . implode($f, ', ');

plugins/mactrack/Net/DNS2/RR/CAA.php:115:        $this->value    = trim($this->cleanString(implode($rdata, ' ')),
 '"');

include/vendor/motranslator-4.0/vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php:56:        return trim(preg_replace('|<.+>|', '', implode($parts, ' ')));

Some of these are part of third party libraries so not something we would fix ourselves normally. Will have to see if there is anything we can submit to them.

netniV commented 4 years ago

Please note, Cacti 1.2.x is not currently tested under PHP 7.4. You will get other errors such as:

https://wiki.php.net/rfc/deprecate_curly_braces_array_access

As that requires a larger change and testing, for now PHP 7.4 is going to throw a lot of errors running Cacti. @paulgevers and @mortenstevens