(When) should I use type hinting in PHP?

前端 未结 6 1979
独厮守ぢ
独厮守ぢ 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:10

    The motivation of the PHP group to add type hinting was to provide people used to Java-style OOP with another feature that would make the platform more familiar, comfortable, and appealing. This, in turn, would make PHP more "enterprise ready", which would help Zend with their core business.

    Marketing aside, it does have its uses. If you're writing a method that operates on a parameter in a specific way that would cause unintended (often silent) failures if the parameter was something else, then using type hinting ensures the code will break during development rather than breaking in production.

提交回复
热议问题