Re: [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Mon, 14 Jul 2014 22:59:43 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-75516@lists.php.net to get a copy of this message
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.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/


Thread (250 messages)

« previous php.internals (#75516) next »