Re: Type hinting
| From: | Etienne Kneuss | Date: | Thu, 27 May 2010 08:10:42 +0000 |
| Subject: | Re: Type hinting | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48490@lists.php.net to get a copy of this message | ||
Hi,
On Thu, May 27, 2010 at 09:45, Arvids Godjuks <arvids.godjuks@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