3 ms·
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
by supriyo-biswas 3y ago
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.
- satvikpendem 3y agoIt'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.
- askonomm 3y agoBut .. PHP doesn't have compile time. It's an interpreted language.
- satvikpendem 3y agoStatic type checking. Javascript / TypeScript is not compiled either.
- askonomm 3y agoDoesn'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/ https://psalm.dev/) or PHPStan (https://github.com/phpstan/phpstan https://github.com/phpstan/phpstan) both offer static type checking.
- enterprise_cog 3y agoTS 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.
- phatskat 3y agoMaybe I’m missing something but isn’t TS compiled to JS?
- morelisp 3y ago> 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.