Skip to content

DateTime::getLastErrors() not returning false when no errors/warnings #9431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Quirinus opened this issue Aug 26, 2022 · 4 comments
Closed

Comments

@Quirinus
Copy link

Quirinus commented Aug 26, 2022

Description

The following code:

<?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.

Either the documentation needs to be corrected, or if it's correct, the bug needs to be fixed.

PHP Version

PHP 8.1.8, PHP 7.4.30

Operating System

No response

@cmb69
Copy link
Member

cmb69 commented Aug 26, 2022

Reported behavior confirmed: https://3v4l.org/qB6HQ

However: https://3v4l.org/1IJQh

I'm not quite sure whether this is expected behavior, or at least something that we will change in the future. @derickr, thoughts?

@derickr derickr self-assigned this Aug 26, 2022
derickr added a commit that referenced this issue Aug 29, 2022
… no errors/warnings

For PHP 8.2 and later only.
@derickr
Copy link
Member

derickr commented Aug 29, 2022

Fixed through 932586c for PHP 8.2 and later only.

@derickr derickr closed this as completed Aug 29, 2022
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Oct 12, 2022
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Oct 13, 2022
JoaoRodrigoGoncalves added a commit to JoaoRodrigoGoncalves/ITAssets-Web that referenced this issue Dec 22, 2022
mantis added a commit to mantis/picofeed that referenced this issue Dec 26, 2022
Return status of getLastErrors has changed - see php/php-src#9431
mantis added a commit to mantis/picofeed that referenced this issue Dec 26, 2022
Return status of getLastErrors has changed - see php/php-src#9431
@W1DJM
Copy link

W1DJM commented Feb 10, 2023

Why was this not ported to the 8.1.x stream also? The bug appears in 8.1.15 also as evidenced by: https://3v4l.org/eU2ra#v8.1.15

@Quirinus
Copy link
Author

Quirinus commented Mar 2, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants