Skip to content

fix: convert DateTimeInterface objects to strings in Entity::toRawArray#10402

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

fix: convert DateTimeInterface objects to strings in Entity::toRawArray#10402
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/8302-toRawArray-datetime

Conversation

@gr8man

@gr8man gr8man commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description
Supersedes #10207. Fixes #8302.

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.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • [] Conforms to style guide

@gr8man gr8man changed the title Fix/8302 to raw array datetime fix: convert DateTimeInterface objects to strings in Entity::toRawArray Jul 10, 2026
@gr8man gr8man force-pushed the fix/8302-toRawArray-datetime branch 4 times, most recently from 2346fdc to d87f3a6 Compare July 10, 2026 21:08
@gr8man gr8man force-pushed the fix/8302-toRawArray-datetime branch from 4c3f524 to 3eceb0c Compare July 10, 2026 21:10
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