Skip to content

Commit 8a4eb21

Browse files
committed
Fix PHP fatal error calling format() on non-object
1 parent 7b04416 commit 8a4eb21

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/models/Status.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BNETDocs\Models;
44

55
use \CarlBennett\MVC\Libraries\Model;
6+
use \DateTimeInterface;
67
use \JsonSerializable;
78

89
class Status extends Model implements JsonSerializable {
@@ -18,14 +19,18 @@ class Status extends Model implements JsonSerializable {
1819
public $version_info;
1920

2021
public function jsonSerialize() {
22+
$timestamp = $this->timestamp;
23+
if ($timestamp instanceof DateTimeInterface) {
24+
$timestamp = [
25+
'iso' => $this->timestamp->format('r'),
26+
'unix' => (int) $this->timestamp->format('U'),
27+
];
28+
}
2129
return [
2230
'healthcheck' => $this->healthcheck,
2331
'remote_address' => $this->remote_address,
2432
'remote_geoinfo' => $this->remote_geoinfo,
25-
'timestamp' => [
26-
'iso' => $this->timestamp->format('r'),
27-
'unix' => (int) $this->timestamp->format('U'),
28-
],
33+
'timestamp' => $timestamp,
2934
'version_info' => $this->version_info,
3035
];
3136
}

0 commit comments

Comments
 (0)