On Thu, 20 May 2021 at 10:17, Ondřej Mirtes <ond...@mirtes.cz> wrote:
> Hi, I’m confused by the syntax, when I read it, I think to myself “I know > this, this is just a method call… oh wait, it’s actually a callable”. It > really makes my head hurt. > I agree with the first point — slightly confusing initially, but I can see myself get used to it. I suggested strlen(=>) as an alternative, not sure if that would cause parsing difficulties. > Also, static analysers already have to reason about current code, so > PHPStan (and Psalm probably too) already supports referencing to callables > as strings (global functions) and arrays (methods): > > $name = 'date'; > $name(1); // Parameter #1 $format of callable 'date' expects string, int > given. > I disagree here: while Psalm can understand what's going on in the above code, callables are definitely (in my opinion) the most hairy part of PHP's type system. The RFC gives an example of something not caught by either PHPStan or Psalm: https://psalm.dev/r/21217fdfb4 https://phpstan.org/r/6cc8cdc2-ecc6-403d-887d-0f12f4813b75 Discouraging this particular formulation would make affected codebases safe from this particular error. Best wishes, Matt