Skip to content

feat: support BackedEnum values in database binds#10256

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-backed-enums
Open

feat: support BackedEnum values in database binds#10256
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-backed-enums

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

Description

This PR adds support for PHP BackedEnum values in database escaping, query bindings, and escaped Query Builder values.

It was inspired by @maniaba's forum post and #10223.

For apps that use native PHP enums for domain values, this makes database code a bit nicer to write:

$db->table('users')
    ->where('status', UserStatus::Active)
    ->get();

CodeIgniter will use the enum's backing value when escaping it, so string-backed enums are treated like strings and int-backed enums are treated like integers.

This avoids repeating ->value at every query call site, while keeping raw SQL and escape-disabled values in the caller's control.

The implementation is intentionally small: enum cases are unwrapped during database escaping, so regular query bindings and escaped Query Builder values use the same existing path.

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

- Allow database escaping to use BackedEnum backing values
- Support BackedEnum values in query bindings and Query Builder binds
- Add focused tests and user guide examples

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant