'php8 supress Warning "Trying to access array offset on value of type bool"
I have the below errors with php 8 that are occuring on one row only of a 150 row table.
I cannot see what is wrong here.
Issue 1
SQL datetime value for column attUpdated 2021-10-06 00:00:00
45 public function getAttUpdatedDate() {
46 $date = $this->sqlData["attUpdated"];
47 return date("M j, Y", strtotime($date));
Deprecated
: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in
C:\xampp3\htdocs\lessons\Ver_92_-_Photo-metadata-fixer-and-Sitemap-Maker\public_html\includes\classes\HelperAttraction.php
on line
47
Issue 2
SQL int(11) value for column attClicksTotal 645
54 public function getAttClicksTotal() {
55 $views = $this->sqlData["attClicksTotal"];
56 $kViews = ($views <= 999) ? ($views) : (round($views/1000) . 'k');
57 return $kViews;
Warning
: Trying to access array offset on value of type bool in
C:\xampp3\htdocs\lessons\Ver_92_-_Photo-metadata-fixer-and-Sitemap-Maker\public_html\includes\classes\HelperAttraction.php
on line
55
Is there a way to block or supress specific php errors, not block all errors but just the two above that seem to be false errors from php. I do not want them showing in the browser?
Note that the code is working and rendering the results of the SQL in the browser correctly but still throwing these errors.
Solution 1:[1]
"Passing null to parameter #1 ($datetime) of type string is deprecated" , i had a similar issue, PHP 8 is strict with NULL values or division by 0 ...
-> return date("M j, Y", strtotime($date));
PHP expects a valid date format, if a NULL or 0 value is passed it may generate an error, you must check the $date variable before using it, ex. if it's null try passing '0000-00-00' or if you're in a loop use continue; to go directly to the next iteration
-> Trying to access array offset on value of type bool
- Here too, you try to access to an array but is not an array, it is a NULL or false value who is returned, the same test it before treatment
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SNS - Web et Informatique |
