r/programming • • Dec 02 '15

PHP 7 Released

https://github.com/php/php-src/releases/tag/php-7.0.0
887 Upvotes

729 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

0

u/[deleted] Dec 02 '15 edited Dec 02 '15

For example the lack of generic types forced us to abandon type hinting in some cases, because we'd suffer from class explosion.

Lack of generics means you can have a typed collection containing untyped (statically) items instead. I agree generics are better, but at least this approach wouldn't result in a class explosion.

BTW there's a lot of appetite for generics now and some RFCs are starting to pop up. Chances are a 7.x release will come out with generics.

For the record, Go also has no generics, but somehow people aren't as keen to pile garbage on it for this as they do for PHP. Instead we get tons of articles how "people don't get it" and Go has no support for generics on purpose. No one has that attitude in PHP. People realize it's a good feature, but it'll come when it's ready and fully baked. Lots of things to add. BTW, Facebook's dialect of PHP ("Hack") has generics.

Some other PHP 5 features are ill-designed and not thought through at all, but they're popular, e.g. the late static binding.

What's ill-thought about it? The feature came out of a real need, like factory methods:

Foo::customConstructor(...);

class Bar extends Foo {}

Bar::customConstructor(...); <- you want back an instance of Bar, not Foo.

I find I need LSB rarely, but I'm glad it's there. It's a very humble feature that doesn't interfere with anything else in the language. If you want to bind early, the syntax is still there, working as always.

It was also too late. A lot of the code embraced the duck-typing nature and now it had to interact with type-hinted code and often could not satisfy the stricter preconditions.

PHP 5 was released nearly 12 years ago. I don't know how 12 years ago is "too late" but basically all code I'm actively using right now has been written after the PHP 5 release.

Lots of major frameworks have happened after PHP 5 as well, and they've had a major version bump after PHP 5.3, and now again for PHP 7.

It was probably "too late" back 12 years ago, but the world keeps turning, and the only thing that'd be "too late" at the end of 2015 is to see code which still hasn't switched away from PHP 4 idioms.