Skip to content

Commit 78ed36b

Browse files
committed
[fix] toArray
1.修復 toArray 判斷順序錯誤,導致包含 UnionType 屬性的物件使用 toArray 時會一律拋錯狀況
1 parent 04aeca5 commit 78ed36b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# CHANGELOG
22

3+
## [v2.4.4] - 2025-09-10
4+
5+
### 🐞 修正
6+
7+
- 修復 `toArray()` 判斷順序錯誤,導致包含 UnionType 屬性的物件使用 `toArray()` 時會一律拋錯狀況。
8+
9+
## [v2.4.3] - 2025-09-03
10+
11+
- 調整專案描述
12+
13+
## [v2.4.2] - 2025-09-03
14+
15+
### 🐞 修正
16+
17+
- 修復 `?array` 傳入 `[]` 時,toArray() 輸出遺失該屬性問題(#2)。
18+
319
## [v2.4.1] - 2025-09-02
420

521
### 🐞 修正

src/ImmutableBase.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,10 @@ final public function toArray(): array
213213
}
214214
}
215215
} else {
216-
if ($property->getType()->isBuiltin()) {
217-
$properties[$key] = $value;
218-
} elseif (is_object($value) && method_exists($value, 'toArray')) {
216+
if (is_object($value) && method_exists($value, 'toArray')) {
219217
$properties[$key] = $value->toArray();
220218
} elseif ($value) {
221-
throw new Exception('不是一種 class 或未提供 toArray 方法');
219+
$properties[$key] = $value;
222220
}
223221
}
224222
});

0 commit comments

Comments
 (0)