Skip to content

Instantly share code, notes, and snippets.

@stephenmelrose
Created March 8, 2013 15:54
Show Gist options
  • Save stephenmelrose/5117425 to your computer and use it in GitHub Desktop.
Save stephenmelrose/5117425 to your computer and use it in GitHub Desktop.
Comparing two objects that have internal date properties with DateTime objects assigned to them. Why does this work?!
<?php
class MyTest {
protected $date;
public function __construct($time) {
$this->date = new DateTime($time);
}
}
$test1 = new MyTest('2013-02-01 00:00:00');
$test2 = new MyTest('2013-03-01 00:00:00');
var_dump($test1 < $test2); // Outputs "true"
var_dump($test1 > $test2); // Outputs "false"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment