Is it possible to write strictly typed PHP code?

后端 未结 9 767
陌清茗
陌清茗 2020-12-14 15:34

For example, is it possible to write code like this:

int $x = 6;
str $y = \"hello world\";
bool $z = false;
MyObject $foo = new MyObject();

9条回答
  •  有刺的猬
    2020-12-14 16:15

    Since the answer is basically "no", an alternative: A PHP "linter", which should catch some of the things a compile-time check would catch in a staticly-typed language like C. Not the same, but should prevent some sillyness

    "Is there a static code analyzer [like Lint] for PHP files" lists many of these.

提交回复
热议问题