Author Topic: Error on firedangerWD.php - I get this error message about 10 times a day  (Read 366 times)

0 Members and 1 Guest are viewing this topic.

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
The following error message is from my site's error_log. This error occurs maybe around 10 times a day:

[05-Jul-2021 17:29:48 UTC] PHP Fatal error:  Uncaught TypeError: Unsupported operand types: string * float in /home/mxo4kz4ohhnx/public_html/firedangerWD.php:98
Stack trace:
#0 /home/mxo4kz4ohhnx/public_html/firedangerWD.php(102): tempToFahrenheit()
#1 {main}
  thrown in /home/mxo4kz4ohhnx/public_html/firedangerWD.php on line 98

Here is my line 98 in firedangerWD.php:

$fTemp = (float)(1.8 * $cTemp) + 32;


Any ideas on how to correct this error?

Offline davidefa

  • Forecaster
  • *****
  • Posts: 436
It should mean that sometime $cTemp has a non numeric value.
A try/catch could be used to log these values

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
The problem endup being an issue with file_get_contents() on the clientraw.txt file. If file_get_contents() fails, it returns FALSE. So several times a day I would get this condition but it wasn't trapped.

The following line would return data from clientraw.txt when it works. If there was a problem $dataraw contained "FALSE", not the data I expect.

$dataraw = file_get_contents($data_file_path);

I just added a line after it:

if ($dataraw == false) {return false;}

 

anything