Johannes,

2013/6/26 Johannes Schlüter <johan...@schlueters.de>:
> So a function author doesn't trust himself and therefore we change the
> language syntax?

In the following example:

class Foo {
    public function bar($input) {
        $return = Baz::foo($input);
        if (!$return instanceof ReturnType)
            trigger_error("Cannot divide by zero", E_USER_ERROR); //
or throwing some RuntimeException

        return $return;
    }
}

Baz class can be from a 3rd party software and I may want to enforce
the fact that my Foo::bar() method returns an instance of ReturnType
or throw an exception or trigger an error.
This is moez easily written with this proposition:

class Foo {
    public function <ReturnType> bar($input) {
        return Baz::foo($input);
    }
}

With the same reasoning you had, you would avoid using parameter type
hinting and interfaces for your own project if there's no other people
using it.

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

Reply via email to