Skip to content

Pass to ColumnInterface::dbTypecast() non-null and non-expression values only #960

Open

Description

@vjik

Seems, all implementations of ColumnInterface::dbTypecast() checks value on null and ExpressionInterface and return it as is for those values:

if ($value === null || $value instanceof ExpressionInterface) {
    return $value;
}

We can check it before call dbTypecast() and simplify simplify both existing implementations and the creation of custom ones.

⚠️ Don't implement it before start version 3.0 development.

Activity

  1. Tigrov commented on Apr 18, 2025

    @Tigrov
    Member

    Any ideas how to realize it?

    Type casting should be fast, this is one of the bottlenecks of AR.
    In current realization it is faster then it was before. It's better to first check if the value matches the expected type, and then cast it to the expected type if necessary.

  2. vjik commented on Apr 18, 2025

    @vjik
    MemberAuthor
    function dbTypecast(ColumnInterface $column, mixed $value): mixed
    {
        if ($value === null || $value instanceof ExpressionInterface) {
            return $value;
        }
        return $column->dbTypecast($value);
    }

    And instead of $column->dbTypecast($value) call dbTypecast($column, $value).

  3. samdark commented on Apr 19, 2025

    @samdark
    Member

    What if I need type-casting for null values?

  4. vjik commented on Apr 28, 2025

    @vjik
    MemberAuthor

    What if I need type-casting for null values?

    If such a case exists, then check only ExpressionInterface

  5. Tigrov commented on Apr 29, 2025

    @Tigrov
    Member

    First, needs to benchmark the current and new approaches.

  6. samdark commented on Sep 4, 2026

    @samdark
    Member

    See #1197

    I think that the null part should be excluded. But ExpressionInterface makes sense. There's only one way to process it properly.

  7. reopened this on Sep 4, 2026
  8. samdark commented on Sep 4, 2026

    @samdark
    Member

    Another way to solve it is to describe it in the PHPdoc so there's at least an implicit requirement. That's actually the case right now:

    If the value is null or an {@see Expression}, there will be no conversion.
    
  9. samdark commented on Sep 4, 2026

    @samdark
    Member

    Likely a solution would be backwards incompatible.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions