Hacker News new | past | comments | ask | show | jobs | submit login

Well, kind of.

I have an old website built on PHP, using a PHP 7 runtime, and I recently had to make a few small changes and discovered PHP had added typing in recent years.

My interest was piqued, and I dug into the docs a bit.

And was promptly disappointed - yes, PHP allows gradual typing, but the type system it has is woeful! Aside from the pitiful selection of types, basically only function arguments can have type hints (e.g. no typing of local vars).




Another huge problem is the lack of typing for arrays.

Considering the prevalence of array types in PHP, this considerably reduces the available safety.

Basically your only option is to use only classes for keyed arrays, and array wrapper classes like `MyClassArray` with typesafe methods like `push` and `get`.

Typescript solves this beautifully generics and interface types.


> the type system it has is woeful

Check out a thing I made: https://psalm.dev. It allows you to add more descriptive types in docblocks.

> no typing of local vars

Why do you want explicit types for local vars?


> Why do you want explicit types for local vars?

I suppose mainly because of deficits in the static analysis tooling that exists (or at least, that I used), as they usually cannot infer types correctly. Psalm looks pretty nice though, so I'll check that out next time I'm working in this PHP codebase :)

Even with exellent tooling though, there are still occasions where I like to use an explicit type.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: