Re: [RFC] Scalar Type Hinting With Casts (re-opening)
From: Andrea Faulds Date: Mon, 14 Jul 2014 14:44:38 +0000 Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening) References: 1 2 Groups: php.internals Request: Send a blank email to internals+get-75466@lists.php.net to get a copy of this message
On 14 Jul 2014, at 15:38, Derick Rethans <derick@php.net> wrote: > I am worried about this big casting conversion matrix. New rules should > not be invented, and the following should *always* be equivalent: > > function foo(typehint $var) > > vs: > > function foo($var) { > $var = typehint $var; > > In general, I am not in favour of casting typehints, as it would be a > different behaviour from the hard-check typehints that we already have > for classes and arrays. I’ve talked about this before in this thread, but the justification for differing in behaviour from array and class hints is that these types are scalars (which PHP routinely juggles) and arrays and objects are not scalar (and not routinely juggled). While we are indeed casting, we’re only doing so where the conversion would be lossless. Sure, it’s not a hard check, but it is still quite strict. I don’t like the idea of completely strict type hints here, but I also don’t think that completely loose type hints that cast and do zero validation are for the best either. This RFC tries to strike a compromise. -- Andrea Faulds http://ajf.me/
Thread (250 messages)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
- RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
- Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| « previous | php.internals (#75466) | next » |
|---|