On 1/4/08, Stanislav Malyshev <[EMAIL PROTECTED]> wrote:
> > There aren't two code models here at all. You can have a function
> > parameter, or you can have a type-enforced function parameter. PHP
>
> So now to use such function you'd have to check your variables for
> typing - otherwise your application blows up. And the type-checking
> should be total - otherwise you miss some call to some function or some
> code path bringing wrong value and your application blows up at runtime
> - since static type checking is not available. Meaning, unless all of
> your code is type-enforced, you'd have to write a wrapper around each
> type-enforced function manually checking that wrong value didn't get in.
>   But you can do the same checks now, so what is the added value?

type-hinting is asserting.
checking of types is needed only on interface-border points (where
type-hints would be used), but usually can be skipped in a lot points
in "private methods"

It's good to be sure, that input-value is exactly the one which is
supposed to be there

currently the typical code is:

public function someMethod($var1)
{
    if (!is_int($var1)) {
        throw new UnexpectedValueException();
    }
    // …
}

it looks too long and (what is even worse) it hides actual
"business-logic" behing checks. I prefer the following code:

public function someMethod(integer $var1)
{
    // …
}

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

Reply via email to