Hi Stephen > Using type hints is a part of the language. It even has benefits that I can > absolutely see being used here: > > array_map(function(Foo $x) => $x->bar()); > > If Foo is a class/interface with a method of bar, your IDE can know that it's > a valid method to call. > > That of course is in addition to the benefit of getting useful type errors > from PHP itself.
I agree but think that this is the wrong approach. PHP is a weakly typed language. Doesn’t it seem wrong that you have to specify types in more places than in many modern strongly typed languages? Look at Swift for example. IMHO, the right approach would be to implement proper closure type hints. This has the benefit of letting the callee specify what kind of closure is expected (who knows that much better than the caller anyway) while allowing for IDE autocompletion. Nonetheless, specifying type hints on the closures is what we do right now. The approach Levi suggested works well with that. > So we should instead use syntax already used for bit wise OR, and further > confuse the situation when the function has no parameters and reusing the > logical OR operator. Brilliant. > > This is still a function, it has slightly different semantics, just like how > a regular function, a class instance method and a static class method have > slightly different semantics: we still use the function keyword for all of > those. > > The static keyword is used for functions, class static properties, static > variables and even static closures: it's semantics are slightly different for > each case but we reuse the same keyword. As Levi already mentioned, this argument is similar to claiming reusing the `function` keyword could be confusing. Both should be perfectly clear to anyone who is serious about programming. I think we can expect for programmers to get informed about new features before using them. This seems to work for any other language. Also, it’s not like the suggested syntax is something we’ve never seen before. Ruby has it, Rust has it (or something similar at least). The rest personal preference I suppose. I can see how people like `function` more because of consistency. I like `|| => expr` more because of readability (for me, the less reading the better :P). @Levi Maybe it would be best to vote for the closure syntax? My least favourite option is better than the RFC getting shot down because people dislike the syntax.