@Stephen Reay <php-li...@koalephant.com>

> And as I said before, I can’t understand how that is supposed to be
better than just doing what works now, using instanceof to check the type
inside the block:
> if (! $foo instanceof Foo) { throw new TypeError(…); }
> At least with the above, it’s obvious what is happening.

It's exactly the purpose of the proposal: avoid this boilerplate. For the
same reason you probably write:

    function test(Foo $foo, string $bar) {}

and not:

    function test($foo, $bar) {
        if (! $foo instanceof Foo) throw new TypeError();
        if (! is_string($bar)) throw new TypeError();
    }

We could have argued a few years ago that adding type-hints to PHP was
unnecessary, for the same reason: if was possible to do these checks in
userland.
It's just much more readable and concise to let the engine perform the
checks.

The current proposal is to fill the gap of type checking / type hinting
**inline**, when getting data from an losely typed source.

- Ben

Reply via email to