RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Tue, 15 Jul 2014 11:18:01 +0000
Subject: RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-75531@lists.php.net to get a copy of this message
> -----Original Message----- > From: Stas Malyshev [mailto:smalyshev@sugarcrm.com] > Sent: Tuesday, July 15, 2014 2:00 AM > To: Andrea Faulds; Chris Wright > Cc: PHP internals > Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) > > Hi! > > > I suggested on IRC that empty strings, TRUE, FALSE, NULL, and values > > that validate for the int type hint could be accepted. Is that a good > > idea? Though it feels a bit loose, I think it covers all the important > > common use cases. > > Then you need to make all internal functions that accept bool work this > way > too. But I'm not sure why you need this. You accept that if("foo") works. > Then > why "function foo(bool $x) { if($x) { ... " should work differently? Yes, > it is an > edge case and bad code style. So are many other legal constructs. In my > opinion, it is better to permit edge cases and be consistent than try to > carve > out perfect set of "what can be boolean" and get lost in the maze of > exceptions and conditions. E.g. if we say we treat 1 and "1" mostly the > same, > then we should say "unless we convert them to bool in a context of a > function > call where they are not". I think it should be kept simpler - if we accept > "foo" > in boolean context, then we should just accept it. Exactly. Zeev

« previous php.internals (#75531) next »