1 | <?php |
||
8 | trait TimedTrait |
||
9 | { |
||
10 | /** |
||
11 | * @var \DateTime |
||
12 | */ |
||
13 | protected $createdAt; |
||
14 | |||
15 | /** |
||
16 | * @var \DateTime |
||
17 | */ |
||
18 | protected $updatedAt; |
||
19 | |||
20 | /** |
||
21 | * Proxy to return given date if defined, formated under given format (if defined) |
||
22 | * |
||
23 | * @param \DateTime $date |
||
24 | * @param string $format optional format |
||
25 | * |
||
26 | * @return \DateTime string |
||
27 | */ |
||
28 | protected function formatDateTime(\DateTime $date = null, $format = null) |
||
35 | |||
36 | /** |
||
37 | * Returns object created at. |
||
38 | * |
||
39 | * @param string $format optional date format |
||
40 | * |
||
41 | * @return \DateTime|string |
||
42 | */ |
||
43 | public function getCreatedAt($format = null) |
||
50 | |||
51 | /** |
||
52 | * Define object created at. |
||
53 | * |
||
54 | * @param \DateTime $createdAt |
||
55 | * |
||
56 | * @return self |
||
57 | */ |
||
58 | public function setCreatedAt(\DateTime $createdAt) |
||
64 | |||
65 | /** |
||
66 | * Returns object updated at. |
||
67 | * |
||
68 | * @param string $format optional date format |
||
69 | * |
||
70 | * @return \DateTime|string |
||
71 | */ |
||
72 | public function getUpdatedAt($format = null) |
||
79 | |||
80 | /** |
||
81 | * Define object updated at. |
||
82 | * |
||
83 | * @param \DateTime $updatedAt |
||
84 | * |
||
85 | * @return self |
||
86 | */ |
||
87 | public function setUpdatedAt(\DateTime $updatedAt) |
||
93 | } |
||
94 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: