(When) should I use type hinting in PHP?

前端 未结 6 1975
独厮守ぢ
独厮守ぢ 2020-12-05 23:42

I can\'t understand the motivation of PHP authors to add the type hinting. I happily lived before it appeared. Then, as it was added to PHP 5, I started specifying types eve

6条回答
  •  情话喂你
    2020-12-06 00:14

    You should use type hinting whenever the code in your function definitely relies on the type of the passed parameter. The code would generate an error anyway, but the type hint will give you a better error message.

提交回复
热议问题