[php-src] Issue #9431: DateTime::getLastErrors() not returning false when no errors/warnings
| From: | Quirinus | Date: | Fri, 26 Aug 2022 12:39:11 +0000 |
| Subject: | [php-src] Issue #9431: DateTime::getLastErrors() not returning false when no errors/warnings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242314@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9431
Author: Quirinus
### Description
### Code
The following code:
```php
<?php
$dateTime = DateTime::createFromFormat('Y-m-d', '2022-08-26');
$lastErrors = DateTime::getLastErrors();
var_dump($lastErrors);
```
Resulted in this output:
```
array(4) {
["warning_count"]=>
int(0)
["warnings"]=>
array(0) {
}
["error_count"]=>
int(0)
["errors"]=>
array(0) {
}
}
```
But I expected this output instead:
```
bool(false)
```
### Discussion
I'm not sure if this is a documentation issue or a PHP bug.
The documentation says that the return type of
DateTime::getLastErrors() is
array|false.
array is returned if there are errors and/or warnings, while false is
returned if there's no errors nor warnings.
In actuality, false is not returned even when there are no errors/warnings - the
array is returned instead, as can be seen in the above example.
### PHP Version
PHP 8.1.8, PHP 7.4.30
### Operating System
_No response_