I am using a php web script that all works successfully. But when I added this: declare( strict_types=1); error_reporting(-1); ini_set('display_errors' , 'true'); PHP: I now see this: Fatal error: Uncaught TypeError: number_format() expects parameter 1 to be float, string given in /home/public_html/sources/videos/content.php:136 Stack trace: #0 /home/public_html/sources/videos/content.php(136): number_format('2.00') #1 /home/public_html/index.php(57): include('/home/.....') #2 {main} thrown in /home/public_html/sources/videos/content.php on line 136 PHP: regarding the last code line here: $html_videos = ''; if (!empty($videos)) { foreach ($videos as $key => $video) { $video = PT_GetVideoByID($video, 0, 0, 0); $html_videos .= PT_LoadPage('videos/list', array( 'ID' => $video->id, 'VID_ID' => $video->id, 'TITLE' => $video->title, 'VIEWS' => $video->views, 'VIEWS_NUM' => number_format($video->views), 'USER_DATA' => $video->owner, 'THUMBNAIL' => $video->thumbnail, 'URL' => $video->url, 'TIME' => $video->time_ago, 'DURATION' => $video->duration, 'PRICE' => number_format($video->video_play_price<$config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price) )); } } Code (markup): Any help with resolving this error is appreciated.
You enabled strict types which affects type coercion (https://stackoverflow.com/questions/48723637/what-does-strict-types-do-in-php/53786924#53786924) number_format() takes an int but you seem to be passing a bool number_format($video->video_play_price < $config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price) Code (markup): It checks if '$video->video_play_price' is less than the result of the if statement '$config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price' and returns true or false which worked before because it would be converted to 0 or 1 and then parsed by number_format().
Try changing it to 'PRICE' => number_format($config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price) Code (markup): It might work, hard to know without seeing the rest of the code.
Thanks for your messages. Greatly appreciated. However, after replacing with you suggested line of code, I see the exact same error. Any additional guidance will be welcomed
It would be hard to know, to see what the values are you can dump them var_dump($config['video_play_price']); var_dump($video->video_play_price); // And maybe die? die(); Code (markup): This will give you an idea of what the values are and if they are integers or not.
One of your 2 number_format uses is returning a "string" instead of a "number". String could be empty. Either 'VIEWS_NUM' => number_format($video->views), or 'PRICE' => number_format($video->video_play_price<$config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price) Your $video is a class variable, probably a result of a query sent before to the database... You should read this, getting float and int values from string variables: https://www.php.net/manual/en/function.floatval.php You can ignore the error by placing the whole code inside a try/catch block, that will catch the error, and you can choose to do nothing about it. However, not good practice by ignoring error if you catch it. By the way, you are in for a lot of work with this strict mode. Good thing is that script will be much stronger, like a hardcore JAVA/c++ script. Also, I don't think your coding skill is enough to do that kind of programming... Sorry to say...