On Wed, Aug 11, 2010 at 8:56 PM, Josh Davis <php...@gmail.com> wrote:
> On 11 August 2010 08:23, Stas Malyshev <smalys...@sugarcrm.com> wrote:
>
>>> I very much can, it's just not my intention. I want to be able to use
>>> type hinting/type checking as a sanity check. If I write a method
>>> whose signature is foo(int $n) I signal my intention to only accept
>>
>> Then you should use statically typed language.
>
> Yeah, hmm, no, and it is disingenuous of you to equate type hints to
> PHP becoming statically typed. I'm sure that some people would love to
> have optional static typing in parts of their code, but I like being
> able to use my vars freely when I need to. Being able to enforce what
> type of arguments can be passed to my functions and methods would
> allow me to cut down on my parameters validation. Similarly, I like
> using protected methods to prevent users [developers using the code]
> from misusing them or protected properties to prevent users from
> inadvertently modifying them, so that I don't have to worry about the
> application being in an inconsistent state.
>
> PHP being dynamically typed shouldn't be an argument to prevent people
> from enforcing method signatures. You're saying that PHP users should
> have no control over what variable types are passed to their
> functions.

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

If you did, can you tell if there is some case, when it doesn't work for you?

The idea is simple:
1) if variable type matches — variable is passed to function
2) if variable can be safely converted to the type, which matches —
variable is converted and passed to the function (you still get
variable of desired type)
3) if variable can not be safely converted — error is raised

error is E_STRICT or E_FATAL (not decided yet). anyway, you can handle
it as fatal in error-handler if you need to

this way you (library developer) get your desired data-types for input
and users get freedom to pass numeric strings instead of numbers
good for everyone

-- 
Alexey Zakhlestin
http://www.milkfarmsoft.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to