4 ms·
> it's typed (now) To note, you'll need strict mode for type hints to be useful. https://www.php.net/manual/en/language.types.declarations.php https://www.php.
by makeitdouble 3y ago
> it's typed (now)
To note, you'll need strict mode for type hints to be useful.
https://www.php.net/manual/en/language.types.declarations.php https://www.php.net/manual/en/language.types.declarations.ph...
The fun part is, instead of going for a generic strict mode system we would have expected, PHP went pragmatic: as most application won't be 100% strict typed, you need to declare it file by file, the icing on the cake being that the restriction applies on the caller of the functions, not the function itself.
It makes for complicated situations, where for instance you can make an utility class that is 100% typed and follows strict typing, but if the caller of your class isn't, none of it will matter and types will be fuzzily coerced anyway.
- muglug 3y ago> To note, you'll need strict mode for type hints to be useful This is not really true — those type hints can be read by static analysis tools, preventing you from many of the issues that would also be caught in strict mode at runtime.
- jwdunne 3y agoYou’re right. Psalm has been a god send on the project I’m working on. Unfortunately, it’s taking far too long for Laravel to catch up so parts of its API are a black hole for types. Especially things like request input, which returns a union of string and array as opposed to using a conditional return type. You end up with assertion soup every time you touch Laravel so over time the project uses less and less of it. A well-typed framework and set of libraries would be very nice.
- muglug 3y ago> Psalm has been a god send on the project I’m working on. Thanks!
- dgb23 3y agoThe type system isn’t expressive enough for these tools to catch anything but the most basic errors. In PHP, typing is for function signature documentation.
- raveren 3y ago> you'll need strict mode for type hints to be useful. false. Utterly false, I don't know where you came up with all of that nonsense. All type hints work as expected, just you can't typehint variables. Only parameters/class properties/return types. And the `strict mode` is a failed experiment no longer recommended in new code (no side effects but no benefits either).