1

Just a question to seasoned PHPers, who have been working with 5- for a while. Has 7 made any difference to the way you code? Are you using any of the new features, and if so, which ones? Are they massive time savers (coding-wise or run-wise) or is it all a bit superficial? Would really like to know. Thanks.

Edited by diafol

4
Contributors
4
Replies
42
Views
6 Months
Discussion Span
Last Post by rubberman
2

Has 7 made any difference to the way you code?

A bit.

To be honest, a part personal code, I have used PHP 7 only for one client's project because it was starting with that version, in that case I used strict type declarations, CSPRNG functions and Throwable to catch common errors.

For me the former and the latter were missing bits in PHP. I'm happy these were introduced. I would like to see Throwable also for warnings and notices rather than setting an error handler.

Are they massive time savers (coding-wise or run-wise)?

At the moment no, not for me.

Something I would like to see is overloading, what is currently used in PHP smells more like overriding and I find it chaotic.

Votes + Comments
About the same here, although not using CSPRNG or strict types
overloading: There isn't the concept of the "method signature" so to add overloading in PHP can be difficult
2

This is a very interesting topic.
I was one of early adapters of PHP 7 and even in one of our production servers. That was due to:
The default PHP 7 OpCache support
The rewriting of threads support (new pThreads)
The scalar type declarations
The rewriting of the engine to be faster and more logical

But in real life projects none of those really mattered. I will not go into details but except from scalar type declarations I realized that none of the above worked the way supposed to work or even to be useful. Even in scalar type declarations , if writing OOP in PHP rarely we pass scalar type to a method and when I do a precise exceptions is being through from inside the method if the type doesn't correspond to what the method expects (remember PHP doesn't have method overloading so in order to have the same result the only way is to evaluate the argument from inside the method).

I found some others aspects of PHP 7 interesting though.

Null coalescing operator: That was something I didn't knew I want , and when figuring out what it is I realized that I always need it.
Spaceship operator: The comparison of two numbers can finally be in a more elegant if / else if

From PHP 5 when useful OOP support came to the language PHP is always programming paradigm agnostic, even in the mixes of it. I have heard Rasmus Lerdorf claiming that this is the strong point of PHP , but it leads to many flavors of the language , almost a different for each programmer / company. After “traits” and “goto” PHP has now also Anonymous classes , I choose not to be part of that ( Lambda Expressions like but in a language that is not event driven) . Also namespaces is in PHP one thing , and they are used in a whole different way , probably PHP is feeling great about that usage (that resembles Java in the semantics (and not in any way substance) , but with no reason at all) and it now has also Group use declarations.
I still can't figure out what they meant to add “Return type declarations" other than that is hack (the programming language) . Everyone that writes in an IDE can add the return value type and I don't quite get to what it can be used.

The great point of PHP 7 is its compatibility , I didn't had to change even a bit of code in a project written in 2008. Of course that was in OOP , using PDO and a reasonable programming approach.

Edited by jkon

Votes + Comments
Null coalescing "??" is great! :)
1

I've been scratching my head a little bit with 7. It may do all sorts of new groovy stuff under the hood, but there's not much in the way of stuff that would transform my approach. Have yet to use spaceship in a project, but itching to give it a go! I don't know what I was expecting from 7, but seeing as 6 was dropped, I thought it would be a little more dramatic. Perhaps I'm missing something (or a few things). As I've been developing WP sites lately, 7 has taken a back seat.

The different ways of programming with PHP certainly make it flexible, but there's heck of a lock more to learn. While you may not use certain paradigms yourself, you need to be aware of them when inspecting 3rd party code. I hope it doesn't get too unwieldy.

0

I started with PHP 5.4.1 some years ago when it first came out. It had a built-in web server that allowed me to test code without a full LAMP stack. It did have home serious errors with its outgoing HTTP code that I had to patch at the source level, but I was able to use it to build a cellphone emulator for Nokia where I worked at the time. From what I am hearing, I look forward to working with version 7. I just hope they fixed those HTTP problems! :-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.