Skip to content

fix: toRawArray() converts DateTime objects to strings (Supersedes #10207)#10400

Closed
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/bug-8302-toRawArray-datetime
Closed

fix: toRawArray() converts DateTime objects to strings (Supersedes #10207)#10400
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/bug-8302-toRawArray-datetime

Conversation

@gr8man

@gr8man gr8man commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Supersedes #10207. Fixes #8302.

Description:
Entity::toRawArray() was returning Time objects instead of primitive strings for date fields. This PR fixes it by converting all DateTimeInterface objects to strings.

Unlike the original PR (#10207), this version safely handles native PHP DateTime objects to prevent Fatal Errors (Object of class DateTime could not be converted to string), by falling back to $value->format('Y-m-d H:i:s') if __toString() is not implemented.

Changes:

  • Safely stringify DateTimeInterface objects in Entity::toRawArray().
  • Added a test case for native DateTime objects.

@gr8man gr8man force-pushed the fix/bug-8302-toRawArray-datetime branch from 734e63a to 1504fb7 Compare July 9, 2026 21:42
This squashes several fixes regarding Entity::toRawArray returning string values instead of Time objects, addressing issue codeigniter4#8302. It also updates DatetimeCast to handle string values to prevent DataConverter crashes, and applies phpstan, rector, and cs-fix formatting.
@gr8man gr8man force-pushed the fix/bug-8302-toRawArray-datetime branch from 1504fb7 to b4560ee Compare July 9, 2026 22:05
@gr8man gr8man closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant