Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is type hinting helping the performance of PHP scripts?

Type hinting helps the compiler to assume the type of the variable, but, as the PHP is a dynamic scripting interpreted language, the question came to my mind if it's possible that type hinting even makes the runtime faster or not?

like image 414
Arsham Avatar asked Aug 27 '10 00:08

Arsham


People also ask

What is type hinting in PHP?

Type hinting is a concept that provides hints to function for the expected data type of arguments. For example, If we want to add an integer while writing the add function, we had mentioned the data type (integer in this case) of the parameter.

When was type hinting added PHP?

In May of 2010 support for scalar type hinting was added to the PHP trunk.

Does PHP have typing?

Because PHP checks the type of variables at runtime, it is often described as a dynamically typed language. A statically typed language on the other hand, will have all its type checks done before the code is executed.

What is type hinting Python?

Type hinting is a formal solution to statically indicate the type of a value within your Python code. It was specified in PEP 484 and introduced in Python 3.5.


1 Answers

PHP is a dynamic language.
Dynamic languages only support runtime checking.
Type hinting is runtime type checking.
Runtime type checking is bad for performance.
Therefore, type hinting is bad for performance.

like image 150
Ming-Tang Avatar answered Oct 11 '22 23:10

Ming-Tang