On Fri, Feb 13, 2015 at 5:59 PM, Andrea Faulds <a...@ajf.me> wrote:

> Hi,
>
> > On 13 Feb 2015, at 16:18, Benjamin Eberlei <kont...@beberlei.de> wrote:
> >
> > Wait i almost forgot, it *does* have an effect on me, especially around
> callback handling:
> >
> > https://gist.github.com/schmittjoh/778e044deacc6f1fe516
> >
> > Essentially callbacks are evaluated in the mode they are called in, not
> in the one they are defined.
>
> This is correct, yes. This is only going to cause a problem, however, if:
>
> * You add type hints despite not knowing what types will be passed
> * You add type hints for the wrong types
>
> In both cases, you have only yourself to blame for your code not working.
> So, I really don’t think it’s an issue. If you don’t know what types will
> be passed, why did you add type hints? If you know what types will be
> passed and added incorrect type hints, why did you expect that to always
> work?
>
> There is of course a third case: the function’s documentation lies and
> claims the function will call your callback with certain types, and
> actually passes different types. However, this is not a problem with the
> RFC, and is something that could happen anyway. At least with this RFC, you
> might discover the bug in the library more quickly due to getting an error.
>
> Anyhow, we could catch such errors prior to call-time by extending the
> callable typehint to take a parameter list, such that parameter type hints
> can be checked (with the same rules as used by inheritance). This would
> solve your problem.
>

Yes, you are right, but think about the same problem in a changing code
base.

What if I pass the closure into a file that is now weak, and then this file
changes to strict.

You argue that hints are only responsible for a single file, but that is
not true. When changing a file to strict, I have to verify that no closures
are passed in that previously relied on weak type hints. Since there is no
interface for callbacks (dynamic invocation) this means reviewing all the
calling code as well.

The same applies to any form of inheritance, see this example:
https://gist.github.com/beberlei/6045bce658026cbdb6ab

The user typehints against a class in weak mode (Foo) and makes use of
that. Now depending which implementation is used (weak or strict) their
code suddenly fails.

Again this example is constructed and probably a bug on parts of the person
building inheritance3.php (class Baz), however you only see this when
calling index.php



>
> Thanks.
>
> --
> Andrea Faulds
> http://ajf.me/
>
>
>
>
>

Reply via email to