Christian Schneider

We have 2 possibilities.
* Throw an error
* Make type conversion

What to select is PHP developers team prerogative.

About example - that's MySQL who is very tollerant, other databases may not
threat well things like passing an ID to numeric field as string. That's bad
style to me. If you have a numeric filed - pass numeric values. If you have
character field - please pass strings. That's more like coding style and
isn't related to this disscussion. And if you have a type-hinted language,
then your ID will be integer anyway or your programm will segfault if you
try to assing a string to int type variable.

We are not talking about MySQL's capability to convert types itself and type
hinting isn't related only to databases - i just took first example I could
think of.

About conversions - see how PHP converts types - that's written in the
manual
echo (int)42; -> 42
echo (int)"42foo"; -> 42
echo (int)"foo"; -> 0
echo (int)"foo42"; -> 0

At least on bad ID's like "foo" or "foo42" you will have 0 and usualy there
are no ids with value 0 in databases, so you will get "No data avaliable" -
that's my approach witch proved to be good one over the years.

Reply via email to