Bug: Entity::toRawArray() may return Time object
Maintainer thường phản hồi trong vòng 1 ngày
@jalexiscv đang làm issue này rồi.
Từ ngày 18/5/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi Entity::toRawArray() với entity User và các trường ngày được hiển thị trong phần tái hiện. Chạy lại chuỗi find, phép gán và toRawArray đã cung cấp, sau đó xác minh rằng updated_at được trả về dưới dạng string như mong đợi thay vì một đối tượng CodeIgniter\I18n\Time.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- PHP
- Star
- 6k
- Fork
- 2k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 59
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của codeigniter4/CodeIgniter4
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
codeigniter4/CodeIgniter4#10616 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
codeigniter4/CodeIgniter4#10618 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
codeigniter4/CodeIgniter4#10617 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
codeigniter4/CodeIgniter4#10615 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
codeigniter4/CodeIgniter4#10589 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của codeigniter4/CodeIgniter4
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
scanaislop/aislop#482 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
humanmade/publication-checklist#73 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Werkstattl/OpenBlogware#92 ·