Since PHP7 we can now use scalar typehint and ask for strict types on a per-file basis. Are there any performance benefits from using these features? If yes, how?
Ar
Are there any performance benefits from using these features? If yes, how?
Not yet.
But this is the first step for a more efficient opcode generation. According to RFC: Scalar Type Hints's Future Scope:
Because scalar type hints guarantee that a passed argument will be of a certain type within a function body (at least initially), this could be used in the Zend Engine for optimisations. For example, if a function takes two float-hinted arguments and does arithmetic with them, there is no need for the arithmetic operators to check the types of their operands.
In previous version of php there was no way to know what kind of parameter could be passed to a function, which makes really hard to have JIT compilation approach to achieve superior performance, like facebook's HHVM do.
@ircmaxell in his blog mentions the possibility of bringing all this to the next level with native compilation, which would be even better than JIT.
From the point of view of the performance, type scalar hints opens the doors for implementing those optimizations. But doesn't enhance performance in and of itself.