On 06/02/2023 21:15, someniatko wrote:
Can you describe some use cases where this feature will be useful? I see it's coming from statically typed / compiled languages like C++, but in such languages compiler must know variable type in order to manage memory properly. As PHP is an interpreted language, it doesn't have this problem.
I'm not convinced the distinction between "compiled" and "interpreted" languages is actually meaningful for modern language implementations - PHP does have a compilation step, and even performs some of its correctness checks at that stage.
Much more important is the distinction between "static typing" and "dynamic typing". The aim of a static typing system is to *prove*, in the mathematical sense, that the program is correct according to the type system of the language, without executing any of the code. The aim of a "dynamic typing" system is instead to *detect* problems in a program, while it is running, and to select operations overloaded based on the actual type of data.
PHP itself currently only includes dynamic typing features - effectively, all the type keywords you add to the source code translate to run-time assertions that check the type of data at specific points. Mostly, that's currently at function boundaries (parameter and return type checking), though typed properties are more complex (especially when you access one by reference, and get a "typed reference").
One of the big implications of that is performance: adding checks in more places (e.g. on every assignment to a local variable), or more complex checks (e.g. checking every element of an array), means that the actual program runs slower. It may be possible to implement checks in a more efficient way, but it's not going to be a simple patch.
That's why including an official static analyser is tempting, but it's not obvious where that would fit in the project and ecosystem (see the recent thread on that topic).
Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php