On 17 Jul 2014, at 00:12, Stas Malyshev <smalys...@sugarcrm.com> wrote:
> I think if the compromise is having multiple set of rules for implicit > casts then this compromise is not worth it. If you answer to the > question of "what happens if I use a string in boolean context" with > "well, it depends, if it's boolean context in syntax construct, it's one > rule, if it's internal function, another, if it's user function, yet > another" - it's not a good compromise. Any solution where you can give > an actual answer like "empty string is false, all others are true" is > much better. I'm not a fan of strict types in PHP, but having > inconsistent rules is IMO so bad that even strict types would be better. > At least you'd then know on which planet you are. To be fair, the RFC as it stands has booleans be strict, with true and false the only allowed values. Also, strings, integers and floats have (IMO) easy-to-explain rules under this RFC.: * bools: bools and objects that convert to bools only * strings: Anything that can be losslessly converted to a string works (any int, float, string, or object with toString) * float: Anything that can be losslessly converted to a float (any int, float, numeric-only string, or object that converts to float) * int: Anything that can be losslessly converted to an int (any int, float that’s integral, integral numeric-only string, or object that converts to int) Actually, objects are a special case here, unfortunately, but I didn’t really have a choice because they cast weirdly. This compares to the current zpp rules (as well as I can remember them, anyway): * bools: Any int, string, float, bool, or object that can cast to bool; if it’s an int, then non-zero is true; if it’s a float, then non-zero is true; if it’s a string, then it’s true unless it’s an empty string or zero * strings: Anything, unless it’s an object that doesn’t implement toString (I think that’s the rule, anyway) * int: Any int, float, bool, object that casts to int, or string that begins with numeric digits (this is sometimes a notice) * float: Any int, float, bool, object that casts to float, or string that begins with float-like digits (this is sometimes a notice) However, I honestly can’t remember zpp’s exact behaviour and I might have made some mistakes there. Is zend_parse_parameters’s behaviour actually documented in the manual? A quick search finds nothing. -- Andrea Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php