Lest not touch the validation topic - it's obvious and we are not
talking about it.

As for the DB - I don't want to write code like this.

// Select from DB
// Start the loop fetch the data
settype('integer', $row['id']);
settype('float', $row['price']);
settype('int', $row['amount']);
settype('integer', $row['order_id']);
// ....
// End of loop here
// Do the data processing

Sorry, but that's just stupid code.

2010/5/27 Daniel Egeberg <daniel.egeb...@gmail.com>:
> On Thu, May 27, 2010 at 10:53, Arvids Godjuks <arvids.godj...@gmail.com> 
> wrote:
>> Heh... Please do a DB select and make a var_dump on the rows from
>> database. You will see things like:
>>
>> array(3) {
>>  ["id"]=>
>>  string(1) "1"
>>  ["ref_id"]=>
>>  string(2) "15"
>>  ["name"]=>
>>  string(7) "Bla bla"
>> }
>>
>> string, string and string again.
>>
>> And that breaks the concept of strict type hinting. Because we get
>> data from DB in STRING type, regardless of the type of the DB fields.
>> And that's my argument for auto-converting type hints when it is
>> possible without data loss. I expect PHP to pass indexes "id" and
>> "ref_id" to function, witch expects int without any notices or errors
>> - just do the bloody thing with converting to int and do your work. If
>> I pass "name" index to that function - it should fail with a Fatal
>> error.
>>
>> So, stop twisting my words and taking sentences out of the context,
>> please! I don't want to argue on things that I described in detail and
>> people just skim them trough just to reply with critics just for the
>> sake of making a reply.
>
> I don't see how I'm twisting your words.
>
> As for the database: Hopefully you know what types you have in your
> database. If you know that a particular column is an int, then casting
> to int is entirely a non-issue.
>
> As for user provided data: Say you ask the user how old he is (that
> would be an int)? If he answers "123abc" then your validation logic
> should catch that he entered an invalid value. Once you've determined
> that it is a valid value, then casting to int is a non-issue.
>
> --
> Daniel Egeberg
>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to