Popularity aside, Perl 6 supports exactly this.
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).
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.
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?
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.