Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vjik opened this issue Apr 17, 2025 · 2 comments
Open

Comments

@vjik
Copy link
Member

vjik commented Apr 17, 2025

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.

@Tigrov
Copy link
Member

Tigrov commented Apr 18, 2025

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.

@vjik
Copy link
Member Author

vjik commented Apr 18, 2025

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).

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

No branches or pull requests

2 participants