[php-src] Issue #8246: PHP Deprecated: number_format(): Passing null

From: Date: Thu, 24 Mar 2022 14:27:50 +0000
Subject: [php-src] Issue #8246: PHP Deprecated: number_format(): Passing null
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240481@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8246 Author: Gilmar-Conectar ### Description The following code: ```php $sql = 'SELECT CLIENT.NAME,SUM(X.TOTAL) FROM SALES X WHERE X.CODCLI = SALES.CODCLI) AS TOTAL FROM CLIENT WHERE CLIENT.CODCLI <10'; $rs = mysqli_query($sql); if ($rs){ while ($row = mysqli_fetch_array($rs)) { echo 'Client: '.$row['NAME']; echo 'Total: '.number_format($row['TOTAL'], 2, ",", "."); } } <?php ``` Resulted in this output: ```Error : PHP Deprecated: number_format(): Passing null to parameter #1 ($num) of type float is deprecated ``` But I expected this output instead: ```0,00 ``` I'm having problems in PHP 8.1, because of the types and functions like preg_replace, stripos, etc. When I do a SELECT with mysqli_fetch_array, there are fields that will return NULL, and this is generating errors in several points of the system that need to use a trim() for example, but the database return is NULL, which is normal to happen. I believe it should continue to treat NULL as a String type in these cases. The same happens with the number_format if it returns NULL in a SELECT statement SUM(), it reports an error, but this happens straight away. ### PHP Version PHP 8.1.4 ### Operating System Windows 10

« previous php.bugs (#240481) next »