codeigniter4 / codeigniter4/CodeIgniter4

Bug: Entity::toRawArray() may return Time object

未關閉
#8,302 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
PHP
星號
6k
分支
2k
平均合併
1 天 11 小時
30 天內合併 PR
73

描述

### 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.

```php
$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 | john@example.co... | US | 2023-12-07 04:0... | 2023-12-07 04:0... | |
+----+------------+--------------------+---------+--------------------+--------------------+------------+
```
```php
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 'john@example.com' (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 'john@example.com' (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 'john@example.com' (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_

貢獻指南

開啟貢獻指南

研究方向

Start by tracing Entity::toRawArray() with the User entity and date fields shown in the reproduction. Re-run the provided find, assignment, and toRawArray sequence, then verify that updated_at is returned as the expected string rather than a CodeIgniter\I18n\Time object.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
mysql, php
領域
backend, database
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。