Why is type hinting necessary in PHP?

前端 未结 6 1654
北恋
北恋 2020-12-05 07:27

I am having trouble wrapping my head around the importance of Type hinting in PHP.

Apparently \'type hinting\' in PHP can be defined as follows:

6条回答
  •  伪装坚强ぢ
    2020-12-05 07:47

    Is it necessary? No

    Is it a best-practice? Yes

    Which PHP version supports it? PHP 5.6 for classes only, PHP 7+ allows type-hinting for primitives (int, string, boolean, etc) as well.

    How is it useful?

    1. Getting hints by the IDE (depends on the IDE).
    2. Standardizing coding style in team projects.
    3. Reducing logic errors.
    4. Moving from PHP being lossy-typed language, to kindof-strongly-typed PHP, but keeping the option to use lossy or strongly at the hands of the developers.

提交回复
热议问题