Skip to content
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

[false-positive] 'type unsafe comparison' on DateTime objects #19

Closed
b1rdex opened this issue Nov 2, 2016 · 5 comments
Closed

[false-positive] 'type unsafe comparison' on DateTime objects #19

b1rdex opened this issue Nov 2, 2016 · 5 comments

Comments

@b1rdex
Copy link
Contributor

b1rdex commented Nov 2, 2016

$date1 = '2016-11-02';
$date2 = '2016-11-02';
(new DateTime($date1)) == (new DateTime($date2))

You can't check DateTime equality, but php allows them to compare using ==, > and <.

@kalessil kalessil changed the title Don't inspect 'type usafe comparison' on objects [false-positive] 'type usafe comparison' on DateTime objects Nov 2, 2016
@dryabov
Copy link
Contributor

dryabov commented Nov 2, 2016

I've checked php sources, there are special comparators for Closure, DateTime, DateTimeImmutable, IntlBreakIterator, IntlTimeZone, PDO, PDOStatement, ArrayObject, and SplObjectStorage classes (search for ".compare_objects" string).

@b1rdex b1rdex changed the title [false-positive] 'type usafe comparison' on DateTime objects [false-positive] 'type unsafe comparison' on DateTime objects Nov 2, 2016
@dryabov
Copy link
Contributor

dryabov commented Nov 2, 2016

And most likely classes extending above ones have the same comparators (but it should be checked, seems it is not explained in docs).

@kalessil
Copy link
Owner

kalessil commented Nov 2, 2016

@dryabov : huge thanks for your research, PHP is keeping to surprise me.

@Rarst
Copy link

Rarst commented Nov 17, 2018

I've noticed "type unsafe comparison" showing up on DateTime objects as of right now, had this regressed since or something?

@kalessil
Copy link
Owner

@Rarst: would you please create a new issue for your case?

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