Re: [RFC] Scalar Type Hints v0.2

From: Date: Fri, 16 Jan 2015 15:37:45 +0000
Subject: Re: [RFC] Scalar Type Hints v0.2
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-80645@lists.php.net to get a copy of this message
Hi again, On Fri, Jan 16, 2015 at 4:52 PM, Rowan Collins <rowan.collins@gmail.com> wrote: > > Specifically, I don't think a library author should be able to tell me that, > just because they're feeling picky, '42' and 42 are not equivalent when > calling their function. It does very little to protect me from genuine > mistakes (passing completely the wrong parameter), and makes my life as user > of the library harder. > With no attempt to argue, I just thought of another example, inspired by the ones given in the RFC - it is fairly common for functions dealing with times to only accept a UNIX timestamp or otherwise just a single kind of a time unit, such as only a count of minutes or days. So where '7 years' is passed and and accepted when using a weak hint (by truncating the trailing non-numeric characters), a strict hint on the other hand may prevent the input of incorrect data (given that it's not years that are expected, of course). While typing that, I thought of another possible improvement that may be made regardless of strict, weak or no scalar type hints are implemented. I'm not sure if it's feasible due to the parser/compiler/whatever possibly not having access to this info, so I hope that somebody confirms that ... Can it be made for the error messages to mention the *parameter name* instead of only its number? Take the following example: function fubar(string $data, int $mode) {} fubar('dummy', 'non-integer'); A 'fubar() expects parameter 2 ($mode) to be integer, string given' would be substantially more useful in case of wrong input. Cheers, Andrey.

« previous php.internals (#80645) next »