Re: Return type hints

From: Date: Tue, 15 Apr 2008 11:28:25 +0000
Subject: Re: Return type hints
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-37022@lists.php.net to get a copy of this message
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.

« previous php.internals (#37022) next »