Re: [PDO] Fixing bug #44639 for mysql

[email protected] (Lukas Kahwe Smith) Wed, 28 Oct 2009 15:14:38 +0100
Newsgroups php.pdo
Message-ID <[email protected]>
On 28.10.2009, at 15:02, Oskar Eisemuth wrote:

> Hello
>
> goran miskovic wrote:
>> As user, I would expect, no meter what, that if a variable type is
>> explicitly given that it must be handled in that way.
>>
>> If I am saying that variable type is integer and I am passing  
>> string then
>> perhaps variable might be converted to integer. However, I would  
>> prefer
>> throwing exception and letting me know that I did something wrong:
>> "Exception: Declared variable type INTEGER, passed variable type  
>> FLOAT (or
>> whatever)".
>>
> My original idea was to throw an Exception too, but I thought it  
> would break PDO to much.
> An E_NOTICE could be send, or PDO gets a strict type checking mode?
>
> I don't think the php internals know if a string can be converted  
> fully or partial to an integer.

well there is is_numeric. and i would say .. if its numeric cast .. if  
it isnt .. throw a warning when in warning mode and an exception when  
in exception mode .. and do nothing in the default mode (the db will  
probably cause the error in that case).

> Anyway an valid integer value in a string shouldn't be rejected, it  
> somehow feels wrong for PHP throwing Exceptions or Errors for "0"  
> suddenly, as PDO mostly thinks anything is a string and returns  
> strings, it should accept the values it produces. :-)
>
>> Let's say that I am explicitly saying PDO::PARAM_INT and I am  
>> passing string
>> with date. In such case, most likely, date string would be  
>> converted to 1 or
>> 0, creating unexpected results and a bug that would be extremely  
>> hard to
>> spot.
>>
> Well I think currently PHP isn't the right language for that, you  
> have to wait for Lukas type checking rfc.

you mean ilia's right?

> It would be nice to have something like a PDO type checking table,  
> but I wouldn't say this is something for a bug fix and needs a good  
> design. PDO2 todolist where are you?

throw it on the brainstorming page on the wiki.

regards,
Lukas Kahwe Smith
[email protected]