Please read more carefully - what I mean that is we deal mostly with numbers witch are represented as strings, because all data that comes from external sources are STRING regardless of actual contents - be that integer or float - no matter. I don't want to make my code look like this:
function doSomeStuffWithDbData(int $id, string $name, int $someFlag) { } $sql = 'SELECT id, name, some_flag, .... FROM table WHERE .....'; $res = mysqli_query($db, $sql); $row = $res->fetch_assoc(); doSomeStuffWithDbData((int)$row['id'], $row['name'], (int)$row['some_flag']); And so on. There is no meaning in doing explicit type casts and then check the type again! Because if you have bogus data like "123abc" with type cast you cast it to 123 integer and you function check for integer will pass without any notice! Hm, it just strike me. If you want a strict type checks, you have to convert your data before you pass it when it comes from outside (and it always does by the way! - databases, request data, files). So basically you will first convert it and then pass to functions to avoid inconsistent type errors. And UPS! Magically you have no errors! because $data = '123abc'; $data = (int)$data; results in pure 123 int. No benefit in using type hints at all. 2010/5/27 Etienne Kneuss <col...@php.net>: > Hi, > > On Thu, May 27, 2010 at 09:45, Arvids Godjuks <arvids.godj...@gmail.com> > wrote: >> Just wanted to remind everyone that option #3 proposed earlier doesn't >> include auto-casting when data loss is happening. >> >> That means: >> >> function hintMe(int $number) { >> } >> >> hintMe(1); >> hintMe("1"); >> hintMe("1.0"); >> hintMe(array(1)); - Error or notice, no array -> int conversions >> hintMe(1.25); - Error or notice because data is lost. >> hintMe("1 abc"); - Error or notice because data is lost. >> >> As I understood the author. So basically we are free of type juggling >> in cases when strait forward conversion can be done. like "1" => 1 >> (int), "20.2" => 20.2 (float). >> We receive a warning or a fatal error when we pass something that >> can't be converted straight forward like 1.01 => 1 (int) or "1 abs" => >> 1 (int), array(20) => 20.0 (float) and so on. The basic concept as I >> understood is: Convert if there is no data loss, else give an error. >> >> So please, stop discussing this, it really annoys to read the same >> thing over and over again. >> >> As I said earlier, I'm against strict type checking and there is a >> good reason for that: As someone already mentioned, in PHP we are >> dealing with strings 90% of the time - GET, POST, data from databases >> or any other external source. We get integers and floats only when >> stuff is initialized or calculated inside the script. For the external >> data we rely on type auto conversion with some additional checks if >> needed (I don't think you will ever check the field type when >> selecting from database, because I know it's type in schema - you just >> use it and rely on automatic conversion). > > 90% of your function calls are involving values with random scalar > types? really ? > > Personally, I think it would be extremely bad code, but actually, I > doubt it's even true. > >> >> So really - can we stop arguing, polish the rules and get to the >> implementation? :) >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > > -- > Etienne Kneuss > http://www.colder.ch > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php