Re: Re: Improving PHP's type system
| From: | Marco Pivetta | Date: | Tue, 19 Apr 2016 22:09:54 +0000 |
| Subject: | Re: Re: Improving PHP's type system | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92500@lists.php.net to get a copy of this message | ||
On 19 April 2016 at 23:47, Zeev Suraski <zeev@zend.com> wrote:
> I fail to see how adding C++ templates to PHP takes it to the next level
> in anything but the complexity scale. Not having them is not preventing
> anybody from doing anything today. Sure, a bunch of frameworks would adopt
> them once they become available - but it will not enable them to do things
> that are radically different from what they're doing today.
>
And the fact that you fail to see it is why you don't see any advantages,
but that's because you are likely unfamiliar with most recent tooling
around static introspection.
Any reflector-based system, such as a serializer, an ORM or just a
dependency injection or configuration loader would be able to do operations
in a much more precise and less complex way.
In Doctrine ORM, having a way to know that a field or parameter is a
string | null or a int | float may be the difference between knowing
what kind of column definition is needed for a field at DB level, without
even need for defining manual mappings.
Having a configuration system that expects to call setters with specific
parameter types can allow the configuration system to validate the given
data upfront, providing meaningful exceptions to the user, without having
to write an entire separate config specification.
Having a serializer that expects certain types of data allows rejecting any
kind of value that is possibly insecure, and would cause a RCE
vulnerability by unserializing a value into something with a malicious
__wakeup in it.
Etc etc.
In general, improving the type system provides a much more interesting and
practical playground for any kind of tool that would rely on static
introspection: IDEs, reflectors, code generators, code inliners,
documentation generators.
The runtime part of this is just a tiny fraction of what is interesting
about improving the type system at all.
Hope that gives some useful context, in order to see where this would
actually be useful.
Cheers,
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/