I would recommend localizing the "check" more to the specific line where this "boolean" (false) result was provided... though both tests provide some support.
It is possible to provide information that doesn't fit the necessary/requested format and the sequence is not the default of 'yy-mm-dd'. This causes $dt to be set to false and therefore $dt->format... will cause the error previously seen.
So, either a test of the existence of the method 'format' for the object, a test of emptiness of the $dt variable, or maybe a test of strict falseness against $dt... I would recommend the first one to further the code becoming more OOP. The second one is more along the lines of where things have been going, though a mixture of the two may be necessary.
But, to prevent php operation from ending, I changed:
Code:
$dt = DateTime::createFromFormat($local_fmt, $products_date_available);
$products_date_available = $dt->format('Y-m-d');
To:
Code:
$dt = DateTime::createFromFormat($local_fmt, $products_date_available);
$products_date_available = 'null';
if (!empty($dt)) {
$products_date_available = $dt->format('Y-m-d');
}
This way, the entered $products_date_available would be attempted to be converted, but if it fails causing $dt === false, then the captured value is a nothing value, though perhaps it should instead be whatever it was before through some sort of notification and return to edit...
Bookmarks