Re: What do we need strict scalar type hints for?

From: Date: Thu, 05 Feb 2015 01:08:51 +0000
Subject: Re: What do we need strict scalar type hints for?
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-81853@lists.php.net to get a copy of this message
Hi, On Thu, Feb 5, 2015 at 2:58 AM, Stanislav Malyshev <smalyshev@gmail.com> wrote: > Hi! > >> Adding another concept, not changing the existing ones. And really, >> it's just simplifying what is already present via is_<typename>() >> runtime checks, making our lives a little bit easier. > > There's a very big difference between allowing to check types (and then > do whatever you wish) and having functions throw fatal errors if types > do not match. > True, but obviously, us who want strict typehints want to be able to do this: function foo(int $bar) { /* ... */ } ... instead of something like this: function foo($bar) { if ( ! is_int($bar)) { trigger_error(sprintf('foo() expects argument 1 ($foo) to be int, %s given', gettype($bar)), E_USER_ERROR); exit(1); } /* ... */ } Hence, simplifying. :) Cheers, Andrey.

« previous php.internals (#81853) next »