Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The only missing thing about PHP types is generics (array<int> and similar) and non-explicit coercions, which can be fixed with `declare(strict_types=1)`. Other than that, all types checks are enforced at runtime, unlike Typescript.


It's not just having types, other libraries have to support them too. Python has type hints but some libraries support them while some don't. While this is true in TypeScript as well, the vast majority of the most used packages have TS types. And I also want my types to be checked at compile time, not runtime. For runtime, I'd just use Zod.


But .. PHP doesn't have compile time. It's an interpreted language.


Static type checking. Javascript / TypeScript is not compiled either.


Doesn't TypeScript get compiled into JavaScript? I thought TSC actually does a compilation, hence the name, TypeScriptCompiler? But anyway, this also exists for PHP. Psalm (https://psalm.dev/) or PHPStan (https://github.com/phpstan/phpstan) both offer static type checking.


TS tries to keep syntax the same as JS. So tsc usually is just stripping types and, depending on settings, transpiling newer JS features to older versions.


That's still called compiling, regardless if the thing it compiles into is similar or not.


Well then PHP has opcache compiling.


Maybe I’m missing something but isn’t TS compiled to JS?


> all types checks are enforced at runtime, unlike Typescript.

You're presenting this as if it's a feature. I think that's a good summary of PHP and its culture's relation to types.




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

Search: