Re: [RFC] Strict type hints (parameter and return value)
| From: | Guillaume Rossolini | Date: | Fri, 20 Jun 2008 08:07:08 +0000 |
| Subject: | Re: [RFC] Strict type hints (parameter and return value) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38446@lists.php.net to get a copy of this message | ||
Hi,
From a user perspective, I agree that this would probably be the most useful
behaviour of all. "Type hint" would then mean*:
Hint at what type the variable should have. If possible, convert it to the
target type; if it is not even compatible, throw an error*.
Regards,
Guillaume Rossolini
On Thu, Jun 19, 2008 at 6:08 PM, Saulo Vallory <saulovallory@gmail.com>
wrote:
> What if by type hint a parameter, php automatically tries to convert the
> argument into that type and throws an exception ONLY if it couldn't be
> done?
>
> for example:
>
> function concat(string $a, string $b)
> {
> return $a.$b;
> }
>
> I can do:
> concat(1,'1');
> concat(2.5,' pigs');
> concat(new ConvertibleToStringObject, 15);
>
> But if I do:
>
> concat(new NonConvertibleToStringObject, 15);
>
> PHP throws an exception saying the function needs a string, but the
> parameter couldn't be converted...
>
> Can this make everybody happy?
>
> Cheers,
>
> Saulo Vallory
>
> On Wed, Jun 18, 2008 at 9:30 PM, Edward Z. Yang <
> edwardzyang@thewritingpot.com> wrote:
>
> > Fabrice VIGNALS wrote:
> > > In mathematic, equal meen the same value AND the same nature.
> > > The follow fact could be frustrating :
> >
> > Usually, context is good enough to disambiguate between the cases. The
> > most prevalent convention in programming languages is = is assignment,
> > and == is comparison (PHP adds === only because of its type-juggling
> > system). Other languages have = as comparison, and := as assignment.
> > Donald Knuth uses = as comparison, and a left arrow (<-) for assignment.
> >
> > --
> > Edward Z. Yang GnuPG: 0x869C48DA
> > HTML Purifier <http://htmlpurifier.org> Anti-XSS
> > Filter
> > [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>