[Solved] FrozenTime object mistery


I found a strange case in a FrozenTime object.

I get data from a find() and I send it to the view as usual. One particular field comes from a MySQL time column.

The table name is sessions and the field is called time.

When iterating the resulset, this column becomes:

object(Cake\I18n\FrozenTime) {

	'time' => '2017-07-14T01:00:50+00:00',
	'timezone' => 'UTC',
	'fixedNowTime' => false


The mistery starts when calling debug($session->time->format('G:i:s')); With this, I get a Call to a member function format() on null error.

While trying to solve the issue, I did:

$moment = $session->time;
debug($moment instanceof \Cake\I18n\FrozenTime);

and I got a true as an answer. Strange to be null (as the error says) if it is actually an object with content. And I expect to be able to run a ->format() on a FrozenTime object.

It’s even more strange when running:

$b = new Cake\I18n\FrozenTime($moment);
debug($moment == $b);

debug($b); returns the same object(Cake\I18n\FrozenTime) showed above, and debug($moment == $b); returns true. And, guess what? $b->format('G:i:s'); works at this point and it returns something like 1:00:50 (as I was expecting when calling $session->time->format('G:i:s'));

Is it a bug? Am I doing something wrong? Why two equal objects behavior in a different manner?

Should I rename the table and/or the field?

Any help will be appreciated. Thank you.



Simple fact: the error was triggered just because ONE time column was returning NULL

It looks easy when you see it :rofl: