Is it possible to write strictly typed PHP code?

后端 未结 9 873
陌清茗
陌清茗 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:01

    No. That syntax will not work.

    You could, theoretically, come up with a system of objects that enforced their own sort of strict typing, but it wouldn't perform and ...why would you want to, anyway?

    If you need strict typing, use a strictly typed language.

提交回复
热议问题