Skip to content

Backport DateTime::getLastErrors() not returning false when no errors/warnings to PHP 8.1.x stream #10558

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
W1DJM opened this issue Feb 10, 2023 · 5 comments

Comments

@W1DJM
Copy link

W1DJM commented Feb 10, 2023

Description

This is the original report for PHP 8.2.1.

This is the fix for 8.2.1.

The following code:

<?php
$dateTime = DateTime::createFromFormat('Y-m-d', '2022-08-26');
$lastErrors = DateTime::getLastErrors();

var_dump($lastErrors);
<?php

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)

As shown at this test URL https://3v4l.org/eU2ra#v8.1.15 version 8.2.2 returns the correct result but 8.1.15 does not.

PHP Version

PHP 8.1.15

Operating System

Windows 10

@Quirinus
Copy link

Quirinus commented Mar 2, 2023

Thanks for opening this.

@W1DJM
Copy link
Author

W1DJM commented Mar 16, 2023

Hate to be a bother but we've now had another drop of the 8.1.x stream and this issue still remains.

@iluuu1994
Copy link
Member

This seems intentional. This behavior was only introduced in PHP 8.2. Backporting it to PHP 8.1 would be a BC break. I'm not sure whether the new behavior was a good idea to begin with... /cc @derickr

@iluuu1994
Copy link
Member

@derickr Please close as a WONTFIX if this is undesired.

@derickr
Copy link
Member

derickr commented Mar 29, 2023

This was a bug fix in PHP 8.2 — the code for date_get_last_errors has been meaning to return false if no warnings or errors were found for the last 16 years:

15 years ago    Derick Rethans  9f979a16bfa│2967│ PHP_FUNCTION(date_get_last_errors)
16 years ago    Derick Rethans  4043f77e36b│2968│ {
3 years ago     Máté Kocsis     2204dbde3bc│2969│     ZEND_PARSE_PARAMETERS_NONE();
                                           │2970│ 
15 years ago    Derick Rethans  9f979a16bfa│2971│     if (DATEG(last_errors)) {
15 years ago    Ilia Alshanets  bbf53bbb041│2972│         array_init(return_value);
15 years ago    Derick Rethans  9f979a16bfa│2973│         zval_from_error_container(return_value, DATEG(last_errors));
                                           │2974│     } else {
16 years ago    Derick Rethans  4043f77e36b│2975│         RETURN_FALSE;
                                           │2976│     }
15 years ago    Derick Rethans  9f979a16bfa│2977│ }

It was finally fixed in a response to #9431 .

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

4 participants