PHP DateTimeImmutable - getLastErrors() Method
The PHP DateTimeImmutable::getLastErrors() method returns an array of warnings and errors found while parsing a date/time string.
Syntax
public DateTimeImmutable::getLastErrors()
Parameters
No parameter is required.
Return Value
Returns an array containing info about warnings and errors, or false if there are neither warnings nor errors.
Example: Parsing a invalid date/time string
The example below shows the usage of DateTimeImmutable::getLastErrors() method.
<?php try { //trying to parsing a invalid date/time string $date = new DateTimeImmutable('103-105-20889'); } catch (Exception $e) { print_r(DateTimeImmutable::getLastErrors()); } ?>
The output of the above code will be:
Array ( [warning_count] => 1 [warnings] => Array ( [7] => Double timezone specification ) [error_count] => 5 [errors] => Array ( [0] => Unexpected character [1] => Unexpected character [2] => Unexpected character [11] => Unexpected character [12] => Unexpected character ) )
❮ PHP Date and Time Reference