Re: What do we need strict scalar type hints for?
| From: | Thomas Bley | Date: | Mon, 02 Feb 2015 21:42:54 +0000 |
| Subject: | Re: What do we need strict scalar type hints for? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81660@lists.php.net to get a copy of this message | ||
Yes, we currently have negative values for invoices and positive for vouchers ...
Christoph Becker wrote on 02.02.2015 22:17:
> Thomas Bley wrote:
>
>> Here is a typical billing example which uses exceptions:
>>
>> <?php
>> ini_set('error_reporting', E_ALL);
>> ini_set('display_errors', 1);
>>
>> addVat('apples');
>>
>> function addVat($amount) {
>> if (!is_int($amount) && !is_float($amount)) {
>> throw new InvalidArgumentException('Argument 1 passed to
>> '.__FUNCTION__.'
>> must be of the type int|float, '.gettype($amount).' given');
>> }
>> return round($amount*1.19, 2);
>> }
>>
>> Instead of multiple strict scalar hints (e.g. function addVat(int|float
>> $amount){...}), I would prefer to have "numeric" as strict type:
>> function addVat(numeric $amount){...}
>
> Have you considered
>
> addVat(-1);
>
> --
> Christoph M. Becker
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>