logoalt Hacker News

idoubtit • today at 3:33 PM • 1 reply • view on HN

Maybe "minimal" was not the right word. I hope the context made clear that I meant the type system was lacking even for basic uses. Here are 3 common cases.

Some PHP functions (e.g. opening a file) return a `resource` type, but PHP has no official way to declare it. So the right way is to declare `mixed` as an official type (which means `any`) and fix that declaration with a phpdoc comment.

Phpdoc provides generics (named "templates", à la C++), e.g. `iterable<Something>` where `iterable` is an official PHP type (which is awfully imprecise without phpdoc).

Phpdoc has tuples and (associative) array shapes, e.g. `@return list{int, \Error}`.

In past PHP versions, the type system was worse because the internal types were ambiguous: types were implicitly nullable, i.e. `string` meant `null|string`. When PHP gradually added sum types, they fixed that ambiguity.


Replies

someothherguyy • today at 3:43 PM

> Phpdoc has tuples and (associative) array shapes, e.g. `@return list{int, \Error}`.

`list<Error>` a `list<T>` is `array<int<0, max>, T>` (some differences in phpstan vs psalm vs mago)