2 ms·
I do not mean to be rude or offensive but are there plans to fix the half-baked type system? I am using PHP7 at work and the ability to annotate functions with
by 72deluxe 7y ago
I do not mean to be rude or offensive but are there plans to fix the half-baked type system?
I am using PHP7 at work and the ability to annotate functions with types is a good idea until you get arrays which can take anything (so you can have an array of who-knows-what) so you can't assume further down the call stack that you're dealing with a known type so have to test what you're dealing with, or objects.
It's a bit of a mess to me and makes reading the code very difficult without running it in a debugger to step through what you're dealing with. Generics or some form of strong typing (which seemed to be what the type annotations and return value types hinted at) would really help, particularly with large projects. I am coming from a C++ background.
Any pointers or tips or documentation for me would be welcome.
If P++ pushes some of this strictness further onto the language then great. It saves me having to do it in code.
- muglug 7y ago> until you get arrays which can take anything There's a widely-used PHPDoc standard for annotating arrays: `Foo[]`, and there are at least three PHP static analysis tools that can correctly interpret those annotations: Psalm (https://psalm.dev https://psalm.dev), Phan (https://github.com/phan/phan https://github.com/phan/phan) and PHPStan (https://github.com/phpstan/phpstan https://github.com/phpstan/phpstan). Phan and Psalm also support a docblock syntax for generics - I wrote about it here: https://medium.com/vimeo-engineering-blog/uncovering-php-bugs-with-template-a4ca46eb9aeb https://medium.com/vimeo-engineering-blog/uncovering-php-bug...
- 72deluxe 7y agoThanks for this! This is just what I was looking to know Thanks!