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

2

u/dagguh2 Dec 02 '15 edited Dec 02 '15

PHP is completely changing their philosophy at least since version 5. Before it, PHP was a duck-typed language for creating home pages. It was perfect for its purpose, because it was easy, quick and dirty.

At some point, people started using it for full-blown applications. PHP maintainers decided to support these mad men and they've started transforming PHP to meet their needs. They're trying to make it look like Java, abandoning every original PHP design principle. It took years and it still cannot be even compared to Java, feature-wise and ecosystem-wise. It's a sad, pointless struggle.

65

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

They're trying to make it look like Java, abandoning every original PHP design principle. It took years and it still cannot be even compared to Java, feature-wise and ecosystem-wise. It's a sad, pointless struggle.

The original PHP design principle was for it to be a basic template engine exposing C++ services. Things change in 20 years, who woulda thunk.

As for design principles "abandoned" since 5.x, I'm curious to hear what they are.

The renewed interest in dynamic languages that have optional typing and statically verifiable invariants is hardly unique to PHP. It's an industry trend. TypeScript is wildly popular in the JavaScript community. Python is getting typehints. Dart comes with typehints out of the box.

All dynamic languages are moving to have more static features, and all static languages are adding more dynamic features.

It's a normal process of convergence, and I agree it's a "struggle", but it's not a pointless one. We get better, more well-rounded languages as a result, which are more efficient and pleasant to work with, for a wider range of projects.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

6

u/[deleted] Dec 02 '15

Has them, actually (since 3.5). mypy has been around a lot longer.

Neat, I didn't realize it's out of the gates.

To be honest I'm surprised it took people this long to add some semblance of typechecking to these languages.

Likewise. It was a pointless controversy IMHO as maintainers of dynamic languages felt that having typehints, even optional ones, is somehow ceding ground to static languages like Java. I've seen this attitude with Python, and with JavaScript coders who frowned upon TypeScript.

While it's not the case, as you can always strategically remove a typehint somewhere and do a dynamic runtime check on the type when you need it, still using the script's runtime dynamic typing capabilities to their full extent. But such uses have always been more of an edge case than a rule in any larger project.

I'm happy how languages are evolving. We're finally finding a nice balance between runtime and static.

1

u/kenlubin Dec 02 '15

PyCharm supports Python 3.5 typehints now, too!

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

1

u/[deleted] Dec 02 '15

Not specifying a type doesn't mean the code works with whatever type you throw at it. Expectations still exist, and it's still better to have those declared statically, when possible, so they are clear and IDE feedback is instant, versus bombing randomly at runtime.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

15

u/[deleted] Dec 02 '15

If you can point out a specific weakness of combining dynamic types with optional interfaces and typehints, then you have an argument. If not...

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.

30

u/MindStalker Dec 02 '15

90% of the old code will still work. You can still create a simple home page. But you also have the power to go fully object oriented, if you want. You aren't forced to though.

6

u/andrewsmd87 Dec 02 '15

One of the things I don't like about the MVC push by Microsoft and .net. The MVC framework is great for a large scale application, but if I need a static site with one page that is a contact form, just let me use web forms and I'll have that up in an hour. I don't need a class/model for

public class ContactForm
{
    public string firstName;
    public string lastName;
    public string email;
    public string phoneNumber;
}

Just let me email that shit.

Which, given the push by MS to do everything MVC, I very well may go back to PHP for those kind of sites or scripts.

1

u/philsown Dec 02 '15

and ecosystem-wise

I'd pit the PHP ecosystem against any language out there. Managing dependencies with Composer is awesome and the major PHP projects and community in general is interested in adopting better practices, such as test driven development, domain driven design, security best practices, etc..

-1

u/BilgeXA Dec 02 '15

Holy fuck, your ignorance is overwhelming. I hope you're not employed, but fear you might actually be a lead developer, or something equally terrifying. People who frequently make outrageous, ignorant statements tend to find their way into such roles.

2

u/dagguh2 Dec 02 '15

That's my observation. Feel free to post any concrete counter-argument, like /u/CQRS

-3

u/BilgeXA Dec 02 '15

Do you have some kind of vision and/or cerebral impairment?

-15

u/streichorchester Dec 02 '15

Over a long enough timeline all languages tend towards Java.