Am Sonntag, den 06.01.2008, 11:28 +0000 schrieb Alain Williams: > On Sat, Jan 05, 2008 at 07:34:04PM -0800, Mike Lively wrote: > > > input is going to makes it's way into your api at some point. Now of > > course you can (and should) be filtering this > > input before it is used, but if imo when dealing with a loosely typed > > language where the same input could be hinted as an > > int in one function it eventually reaches, and a string in another. > > > The point being I understand you may be targeting 'internal stuff' but > > programming (especially web development) is > > centered around manipulating/reading input to perform actions...just > > because it's not 'intended' doesn't mean it's going > > to never happen. > > > Also, I am pretty sure PDO returns results from at least mysql and sqlite > > as strings regardless of their type in the > > database...or are results from the database also not something type hints > > are inteded for? > > PLEASE READ CAREFULLY > > You have NOT understood what type hinting is about. > > You are confusing the TYPE and the VALUE. > > What type hinting means is: > > * is the TYPE correct ? If so succeed. > > * can the VALUE be 100% converted to the desired TYPE (eg '5' to int) ? If so > succeed. > > * fail > > Type HINTING is not type ENFORCEMENT. PHP type juggling is still allowed, so > PDO returning results as strings > is quite OK as long as what is defined to be numeric *really* has a VALUE > that is a number.
You may consider a virtual type like 'numeric' for it, but numeric strings do NOT always behave like integers, so passing a string, when my typehint says int, may cause lots of confusion - Stefan already said this earlier. A simple example: $ php -r 'var_dump( ~"1", ~1 );' string(1) "�" int(-2) Or: $ php -r 'var_dump( "1" ^ "2", 1 ^ 2 );' string(1) "" int(3) And those operations are used quite a lot, when you work with bitmasks in your application. -- Kore Nordmann (GPG 0xDDC70BBB) "Der Hammelherde muss derjenige Hammel, den der Schaefer besonders gut fuettert und der darum zweimal so dick wird wie die Anderen, als Genie erscheinen." Tolstoi (Krieg und Frieden)
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil