Open 8ctopus opened 2 years ago
Sounds like a fair point cc @Girgias
From the docs:
All values are treated as PDO::PARAM_STR.
So not a bug, but rather a feature request. Still, only treating values of type bool
as PDO::PARAM_BOOL
and all others as PDO::PARAM_STR
would be more confusing than as it's now. However, how to map other types is not necessarily clear.
@cmb69 Sorry I overlooked the mention in the documentation. I see 2 options:
IMO it would be convenient for execute()
not to convert all types to string but keep the native type, however I imagine it can cause problems when migrating existing code to newer php versions (unless the new behavior gets implemented in a new method name).
@cmb69 I've given the problem some thought over the weekend and here's what I came up with.
My understanding is that it is not possible to pass a boolean value to execute() without the SQL query failing therefore it should qualify as bug or otherwise the documentation should be updated mentioning that query parameters containing booleans need to be bound manually.
What do you think?
My understanding is that it is not possible to pass a boolean value to execute() without the SQL query failing […]
I'm not sure whether the query fails for all drivers. Maybe we should have a test case for that so we can run it in CI which covers all (?) bundled drivers at least.
otherwise the documentation should be updated mentioning that query parameters containing booleans need to be bound manually.
Is this only an issue wrt. to bools? Would all drivers handle other types (e.g. int) correctly?
Description
The following code:
Resulted in this output:
But I expected execute() not to throw an error.
I clearly see the problem in the source as the parameter is always set to be a string on line 424:
https://github.com/php/php-src/blob/615b8006c42715b5ea9ec61f9368582eeef8467f/ext/pdo/pdo_stmt.c#L411-L425
Can't the execute() code be improved to check for the param type like it is done in bindValue()?
https://github.com/php/php-src/blob/615b8006c42715b5ea9ec61f9368582eeef8467f/ext/pdo/pdo_stmt.c#L1465-L1475
PHP Version
8.2.0 RC3
Operating System
Alpine Linux