Skip to content

Commit 7120e64

Browse files
committed
Fix Response
1 parent 98725d1 commit 7120e64

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Response/Response.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Microwin7\PHPUtils\Response;
44

5+
use stdClass;
6+
57
class Response
68
{
79
private static array $data = [];
@@ -44,11 +46,11 @@ private static function header(): void
4446
}
4547
public static function json_encode(mixed $data = null): string
4648
{
47-
return json_encode((object)null === $data ?: self::$data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION);
49+
return json_encode(null !== $data ? $data : (!empty(self::$data) ? self::$data : new stdClass), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION);
4850
}
4951
public static function response(mixed $data = null)
5052
{
5153
self::header();
52-
die(self::json_encode((object)null === $data ?: self::$data));
54+
die(self::json_encode(null !== $data ? $data : (!empty(self::$data) ? self::$data : new stdClass)));
5355
}
5456
}

0 commit comments

Comments
 (0)