Skip to content

Bug 65548 #439

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
wants to merge 1 commit into from
Closed

Bug 65548 #439

wants to merge 1 commit into from

Conversation

bor0
Copy link
Contributor

@bor0 bor0 commented Sep 11, 2013

https://bugs.php.net/bug.php?id=65548

Added separate functions for DateTimeImmutable that are needed for comparison

@nikic
Copy link
Member

nikic commented Sep 12, 2013

I think this can be solved a bit easier. You should be able to keep one compare handler for both and just remove this part from it:

if (Z_TYPE_P(d1) == IS_OBJECT && Z_TYPE_P(d2) == IS_OBJECT &&
    instanceof_function(Z_OBJCE_P(d1), date_ce_immutable TSRMLS_CC) &&
    instanceof_function(Z_OBJCE_P(d2), date_ce_immutable TSRMLS_CC)) {

The IS_OBJECT checks are unnecessary (compare_objects is only invoked on ... objects).

If you do it this way, then a DateTime and a DateTimeImmutable with the same values would be considered equal (I assume that is a behavior we want, right?)

@bor0
Copy link
Contributor Author

bor0 commented Sep 12, 2013

PR updated as suggested. I thought of that, but I was thinking that IS_OBJECT might cause harm if removed. Another thing, question is if it's worth to consider, is the "Trying to compare an incomplete DateTime object" string, should we try to detect instance_of and use DateTime or DateTimeImmutable accordingly?

@nikic
Copy link
Member

nikic commented Sep 12, 2013

@derickr could you review this?

php_date_obj *o2 = zend_object_store_get_object(d2 TSRMLS_CC);

if (!o1->time || !o2->time) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to compare an incomplete DateTime object");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this can now be for both, the error message should include both DateTime and DateTimeImmutable.

@derickr
Copy link
Member

derickr commented Sep 12, 2013

Besides the comments, this should not go to master, but to every branch that has DateTimeImmutable.

@bor0
Copy link
Contributor Author

bor0 commented Sep 12, 2013

Updated PR. Let me know if any additional changes are needed.


if ($a < $b) {
print("yay");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests should use four-space indentation instead of tabs. The initial indentation level also shouldn't be there.

Furthermore I would suggest doing a comparison between a DateTime and a DateTimeImmutable here too and some more tests in general.

E.g.:

<?php

$iToday = new DateTimeImmutable('today');
$iTomorrow = new DateTimeImmutable('tomorrow');

$mToday = new DateTime('today');
$mTomorrow = new DateTime('tomorrow');

var_dump($iToday < $iTomorrow);
var_dump($iToday == $iTomorrow);
var_dump($iToday > $iTomorrow);

var_dump($iToday == $mToday),
var_dump($iToday === $mToday);

var_dump($iToday < $mTomorrow);
var_dump($iToday == $mTomorrow);
var_dump($iToday > $mTomorrow);

?>

With output true, false, false, true, false, true, false, false.

@bor0
Copy link
Contributor Author

bor0 commented Sep 12, 2013

Test updated.

Added separate methods for DateTimeImmutable that are needed for comparison
@php-pulls
Copy link

Comment on behalf of nikic at php.net:

Applied patch: d7f5f1e

Thanks for working on this!

@php-pulls php-pulls closed this Sep 12, 2013
@kaplanlior
Copy link
Contributor

I'm glad to see how quickly this PR was reviewed, fixed and merged. Thanks everyone!

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

Successfully merging this pull request may close these issues.

5 participants