On 11 August 2010 19:11, Alexey Zakhlestin <indey...@gmail.com> wrote: > Did you read second RFC? The one which is about "so called" weak typehinting. > Stas (and a lot of people on this list) prefer it. > http://wiki.php.net/rfc/typecheckingstrictandweak
Yes of course, but reposting that link is a good idea. :) > If you did, can you tell if there is some case, when it doesn't work for you? If I'm using type checking as a sanity check then it doesn't work as soon as it accepts "1" for an int. The described "weak typehinting" is good if you're looking for a way to validate input. However, it does not work if you're trying to make sure that Stuff Is Going As Planned(tm). For example, consider a protected method getTheNextNTokens(int $n) which is part of some tokenizer or something. It is a protected method and you never write getTheNextNTokens("2") so if it ever receives something that is not an integer, it means that there's a subtle bug somewhere. In that case, "strict typehinting" buys you peace of mind. If your function lives in a controlled environment (e.g. private methods, or because your specifications require to use the filter extension to validate input) then checking for the type of a variable offers more protection against the unexpected than checking for its contents. Of course, it's not an absolute protection, just like making a method private does not guarantee that a user [of your code] won't extend it to make it public or use ReflectionMethod to make it accessible. It's just another way to defend against the unexpected. I hope it answers your question :) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php