Bug: Entity::toRawArray() may return Time object
維護者通常 1 天內回覆
@jalexiscv 已經在處理了。
開始於 2026年5月18日。
評估
研究方向
首先,使用重現中顯示的 User entity 和日期欄位追蹤 Entity::toRawArray()。重新執行提供的 find、指派和 toRawArray 序列,然後確認 updated_at 回傳的是預期的 string,而不是 CodeIgniter\I18n\Time 物件。
由索引模型根據 Issue 內容生成。
描述
PHP Version
8.1
CodeIgniter4 Version
4.4.3 and develop
CodeIgniter4 Installation Method
Git
Which operating systems have you tested for this bug?
macOS
Which server did you use?
cli-server (PHP built-in webserver)
Database
MySQL 8.0.34
What happened?
The following code returns Time object.
$user->updated_at = '2023-12-12 12:12:12';
var_dump($user->toRawArray());
Steps to Reproduce
+----+------------+--------------------+---------+--------------------+--------------------+------------+
| id | name | email | country | created_at | updated_at | deleted_at |
+----+------------+--------------------+---------+--------------------+--------------------+------------+
| 1 | John Smith | [email protected]... | US | 2023-12-07 04:0... | 2023-12-07 04:0... | |
+----+------------+--------------------+---------+--------------------+--------------------+------------+
<?php
namespace App\Models;
use App\Entities\User;
use CodeIgniter\Model;
class UserModel extends Model
{
protected $table = 'user';
protected $returnType = User::class;
protected $allowedFields = [
'name',
'email',
'country',
];
// Dates
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
}
<?php
namespace App\Entities;
use CodeIgniter\Entity\Entity;
class User extends Entity
{
protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [];
}
public function index()
{
$users = new UserModel();
/** @var User $user */
$user = $users->find(1);
var_dump($user->toRawArray());
$user->updated_at = '2023-12-12 12:12:12';
var_dump($user->toRawArray());
$user = $users->find(1);
var_dump($user->toRawArray());
}
/Users/kenji/work/codeigniter/official/CodeIgniter4/app/Controllers/Home.php:15:
array (size=7)
'id' => string '1' (length=1)
'name' => string 'John Smith' (length=10)
'email' => string '[email protected]' (length=16)
'country' => string 'US' (length=2)
'created_at' => string '2023-12-07 04:00:48' (length=19)
'updated_at' => string '2023-12-07 04:00:48' (length=19)
'deleted_at' => null
/Users/kenji/work/codeigniter/official/CodeIgniter4/app/Controllers/Home.php:18:
array (size=7)
'id' => string '1' (length=1)
'name' => string 'John Smith' (length=10)
'email' => string '[email protected]' (length=16)
'country' => string 'US' (length=2)
'created_at' => string '2023-12-07 04:00:48' (length=19)
'updated_at' =>
object(CodeIgniter\I18n\Time)[88]
protected 'timezone' =>
object(DateTimeZone)[90]
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
protected 'locale' => string 'en' (length=2)
protected 'toStringFormat' => string 'yyyy-MM-dd HH:mm:ss' (length=19)
public 'date' => string '2023-12-12 12:12:12.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
'deleted_at' => null
/Users/kenji/work/codeigniter/official/CodeIgniter4/app/Controllers/Home.php:21:
array (size=7)
'id' => string '1' (length=1)
'name' => string 'John Smith' (length=10)
'email' => string '[email protected]' (length=16)
'country' => string 'US' (length=2)
'created_at' => string '2023-12-07 04:00:48' (length=19)
'updated_at' => string '2023-12-07 04:00:48' (length=19)
'deleted_at' => null
Expected Output
Returns string value '2023-12-12 12:12:12'?
Anything else?
No response
- 主要語言
- PHP
- 星號
- 6k
- 分支
- 2k
- 平均合併
- 1 天 22 小時
- 30 天內合併 PR
- 59
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeigniter4/CodeIgniter4 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
codeigniter4/CodeIgniter4#10616 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
codeigniter4/CodeIgniter4#10618 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
codeigniter4/CodeIgniter4#10617 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
codeigniter4/CodeIgniter4#10615 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 48/100
codeigniter4/CodeIgniter4#10589 · 3 則留言 ·
維護者通常 1 天內回覆
查看 codeigniter4/CodeIgniter4 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
woocommerce/woocommerce-google-analytics-integration#699 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 60/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
ProfessionalWiki/NeoWiki#1675 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 70/100