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);