Skip to content

Commit 12aa25d

Browse files
committed
fix: Disable casting when an $casts is empty
1 parent 027a0f2 commit 12aa25d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

system/Entity/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ protected function castAs($value, string $attribute, string $method = 'get')
578578
*/
579579
protected function dataCaster(): ?DataCaster
580580
{
581-
if (! $this->_cast) {
581+
if ($this->casts === [] || ! $this->_cast) {
582582
$this->dataCaster = null;
583583

584584
return null;

user_guide_src/source/changelogs/v4.7.0.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ your code.
114114
Entity and DataCaster
115115
---------------------
116116

117-
Previously, the ``DataCaster`` object was always initialized, even if you did not use the ``$_cast = false`` type casting.
117+
Previously, the ``DataCaster`` object was always initialized, even if you did not use the type casting:
118+
configured ``$_cast = false`` or having an empty array ``$casts = []``.
118119
Now, the object is created on-demand and deleted when type casting is disabled.
119120
In general, the change does not break the existing process, it should be remembered that now in some cases ``$dataCaster`` may be nullable.
120121

@@ -207,6 +208,11 @@ Method Signature Changes
207208
- ``prepare(): void``
208209
- ``respond(): void``
209210

211+
Property Signature Changes
212+
==========================
213+
214+
- **Entity:** The protected property ``CodeIgniter\Entity\Entity::$dataCaster`` type has been changed from ``DataCaster`` to ``?DataCaster`` (nullable).
215+
210216
Removed Deprecated Items
211217
========================
212218

@@ -309,7 +315,6 @@ Changes
309315
*******
310316

311317
- **Cookie:** The ``CookieInterface::EXPIRES_FORMAT`` has been changed to ``D, d M Y H:i:s T`` to follow the recommended format in RFC 7231.
312-
- **Entity:** The protected property ``CodeIgniter\Entity\Entity::$dataCaster`` can be nullable.
313318
- **Format:** Added support for configuring ``json_encode()`` maximum depth via ``Config\Format::$jsonEncodeDepth``.
314319
- **Paths:** Added support for changing the location of the ``.env`` file via the ``Paths::$envDirectory`` property.
315320
- **Toolbar:** Added ``$disableOnHeaders`` property to **app/Config/Toolbar.php**.

0 commit comments

Comments
 (0)