Why is type hinting necessary in PHP?

前端 未结 6 1662
北恋
北恋 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:59

    Type hinting is like the name says more of a hint. It allows developers to see what classes may be passed as arguments and prevents them from passing wrong arguments. Thats especially helpful if you're working on the same project with more than just one person and/or the code is meant for open source.

    In php7 type hinting for string, int, (mixed) and array have been added so you don't need only classes but also can use the standard php types

提交回复
热议问题