From 9eb79f02cafa9e623ae22fcee0d7e6c9da84e19d Mon Sep 17 00:00:00 2001 From: ChanthornAcademy Date: Fri, 1 Sep 2023 15:28:47 +0700 Subject: [PATCH] fixed some bugs --- Demo.php | 2 +- src/ToKhmerDate.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Demo.php b/Demo.php index b518a6b..dba8c7e 100644 --- a/Demo.php +++ b/Demo.php @@ -12,5 +12,5 @@ echo khmerDate('2024-01-01')->format(); print_r(khmerDate('2024-01-01')::khNewYear()); - +// or print_r(KhmerNewYearDate(2024)); diff --git a/src/ToKhmerDate.php b/src/ToKhmerDate.php index 360e549..8976cfa 100644 --- a/src/ToKhmerDate.php +++ b/src/ToKhmerDate.php @@ -87,6 +87,11 @@ public static function format(string $format = ''): string }, ]; $result = preg_replace_callback('/[a-zA-Z]/', function ($matches) use ($formatRules) { + + // fix Undefined array key + if (!isset($formatRules[$matches[0]])) { + return $matches[0]; + } return $formatRules[$matches[0]](); }, $format); return Constant::postformat($result);