RE: [PHP-DEV] Reviving scalar type hints

From: Date: Tue, 17 Feb 2015 18:55:45 +0000
Subject: RE: [PHP-DEV] Reviving scalar type hints
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-82999@lists.php.net to get a copy of this message
> De : François Laupretre [mailto:francois@php.net] > > This way, the user can write : > > function convertToInt(string $number): int! { <- int! instead of int > if (!preg_match("(^[0-9]{1,17}$)", $number)) { > throw new InvalidArgumentException("Supplied argument is not a valid > number"); > } > return $number; A static analyzer would raise an error on this, as we are sure it fails, while : function convertToInt(string $number): int! { if (!preg_match("(^[0-9]{1,17}$)", $number)) { throw new InvalidArgumentException("Supplied argument is not a valid number"); } return (int)$number; would be analyzed as OK. That's what you want, don't you ? Regards François

« previous php.internals (#82999) next »