What is the meaning of type hinting in PHP?

Forums PHPWhat is the meaning of type hinting in PHP?
Staff asked 3 years ago

Answers (2)

Add Answer
Prince Dhameliya Marked As Accepted
Staff answered 3 years ago

Type hinting isn’t required, but it can allow you to catch certain types of mistakes. For example, you might have a function or method which requires an integer. PHP will happily convert “number looking strings” into integers, and this can cause hard to debug behavior. If you specify in your code that you specifically need an integer, this can prevent those kinds of bugs in the first place. Many programmers consider protecting their code in this way to be a best practice.

Staff answered 3 years ago

Type Hinting

  • In simple terms, type hinting instructs functions to accept only the specified data type.
  • In more technical terms, Type Hinting is a technique for forcing a function to accept the appropriate data type.
  • Type hinting is available in PHP for Object, Array, and Callable data types.

Subscribe

Select Categories