Skip to content

Fix Entity::toRawArray() returning a Time instance for assigned date attributes - #10772

Open
kushkrg wants to merge 1 commit into
codeigniter4:developfrom
kushkrg:fix/issue-8302-entity-torawarray-time
Open

kushkrg wants to merge 1 commit into
codeigniter4:developfrom
kushkrg:fix/issue-8302-entity-torawarray-time

Conversation

@kushkrg

@kushkrg kushkrg commented Nov 12, 2026

Copy link
Copy Markdown

Summary

$user->updated_at = '2023-12-12 12:12:12';
$user->toRawArray(); // returned a Time instance for updated_at

When a date attribute is assigned at runtime, __set() mutates it to a Time instance before storing it, while the same attribute holds a plain string when the entity is populated from the database via injectRawData(). toRawArray() therefore returned different types for the same attribute depending on how the value got there.

Changes

  • Entity::toRawArray() now normalizes Time instances held in $dates attributes back to their string representation, so the raw value is a string in both cases. The mutation-on-set behaviour itself is unchanged (existing tests assert the stored attribute is a Time instance), and retrieval through __get() still returns Time.
  • Regression test testToRawArrayReturnsStringForAssignedDateAttribute.
  • Changelog entry in docs/changelogs/v4.7.7.md.

Verified locally: EntityTest passes (139 tests, 333 assertions).

Fixes #8302

@carson-codeigniter4 carson-codeigniter4 Bot added needs template Opened issues not following the bug form template stale Pull requests with conflicts labels Nov 12, 2026
@carson-codeigniter4

Copy link
Copy Markdown

👋 Hi, @kushkrg!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch


Hi there, @kushkrg! 👋

It looks like this pull request does not follow our template:

Please update the description to follow the template. The needs template label will be removed automatically once it does.


Hi there, @kushkrg! 👋

Thank you for sending this PR!

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs template Opened issues not following the bug form template stale Pull requests with conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant