📜 ⬆️ ⬇️

Possible future for PHP


Image taken from wikimediafoundation.org

From the translator : this post is a free translation of the article A possible future for PHP , written by Frank Karlitschek, the founder of ownCloud and the developer of the same open source product for creating cloud storage.


If you look at the latest statistics OwnCloud is one of the largest open source projects written in PHP. Most of you know that PHP is used to implement the OwnCloud server side. We use other technologies, such as C ++ and Qt for desktop clients, Java for Android applications and Objective-C for iOS, JavaScript for the web interface and much more. But the heart of OwnCloud is a server component that is based on PHP 5.3 or higher ...
')


There were several reasons for choosing PHP:


PHP is not the most “hit” programming language in the world. In fact, the opposite is true. He has a relatively bad reputation. I personally have never been a big fan in choosing technologies based on the fact that it is “cool” or it is “modern” or it is “in fashion”. I think that there are different technologies for different areas, and they should be evaluated objectively and should be chosen without the involvement of emotions. So I don’t understand religious discussions, why tool X is always better than technology Y. I think that all this is the right technology to work with, of course, after a fair assessment of the rationality of using them.

So I am still very pleased with this decision to use PHP. Until now, we have not encountered major architectural or technical problems that we could not solve with PHP.

But does this mean that PHP is perfect and I am very happy with everything? Of course not. PHP was developed in the mid-90s, at a time when no one could imagine the web as it looks today. Some of the interesting features of the time turned into a nightmare today. There is a lot that needs to be improved, and I think that even the core PHP developers will agree with me here.

Some obvious flaws:

while ( ($filename = readdir($dh)) == true) $files[] = $filename;

I really want to see PHP move to the next level in the future and improve some of these flaws, because most of them really deserve it.
But it is very important to do it right.

The latest article in ArsTechnica and Apple is pushing for Swift as the successor to Objective-C, and here I can see how the next generation of PHP can and should be done.
Maintain backward compatibility or fix its flaws? - Apple Swift

Now there is an old, and frankly, very naive approach. The core team of developers of the programming language simply releases a new incompatible version that corrects the flaws of the old version. Examples are Perl and Python. The problem is that it is almost impossible to rewrite most of the software projects written in these languages, in order to make them compatible with the new version. So you end up working with two versions of the programming language / framework / application for a very long time. And some applications work on the old version and will work on the old version. Different library dependencies are sometimes available only for one of the versions.

Migration is very hard and cannot be done in parts. Please see Perl6 and Python 2/3 for an example of what a nightmare it can be. Both exist for a very long time and many projects are “stuck” somewhere in the middle of the migration route.

A more positive example is C ++. It is still very different from C, but it’s good that it can be used intermixed inside an application. Thus, C 90s developers can use new interesting C ++ functions in one part of the application, without having to rewrite the entire application from scratch.

Apple is moving to promote Swift as a successor to Objective-C, in my opinion, this is very clever. It's a completely new language, but it works in the same runtime environment. This means that a developer can take an existing Objective-C application code and simply start writing new Swift functions or replace some parts of the old code with others with new Swift code. This is ultimately compiled into binary code, which has no new execution dependencies compared with Objective-C.

I hope PHP will do what makes it possible to significantly develop and improve the language, but still providing a smooth migration experience, not like with Perl and Python, when they released completely new incompatible releases.

It is also a good solution if PHP 6 or 7 introduces a new opening tag, for example <? PHPNEXT instead of <? PHP. Both modes will be fully supported by the new version of PHP and can be used in parallel in the same application or even in the same file. And in the PHPNEXT section, a new and improved syntax will be used.

Here are some improvement ideas I'd like to see:


Some of these improvements have been implemented in Hack, which is a kind of separate PHP branch developed by Facebook. Hack has a really interesting concept that is developing in the same direction. They also use the new tag "<hh", so that the code can be used intermixed in one file, and they also improved typing. At the moment it is not clear how much effort Facebook intends to spend on the project in the future in order to develop Hack further and how it will be accepted outside of Facebook. I also worry about how open they are for changes that are not important to them, who will regulate them and how. I would prefer an official and more general approach from the PHP community, which will be part of one of the following major PHP releases.

I hope that the dream of a more modern and clean PHP, including a smooth migration path, will become a reality in the next few years.

Obviously, we in OwnCloud will not be able to start migrating to this new PHP mode, until up to 95% of all PHP installations start working with the new version. It will be easy, but will require an additional 3-5 years.

Making great projects, such as WordPress or OwnCloud, it will actually be possible to move to a cleaner and more modern language. But more importantly, PHP will be ready to challenge the future.

UPD: added a note about removing safe_mode in 5.4.0. Thanks to Sway for the tip-up :), also added a note about filter_input , thx AmdY for the comment .

UPD2: corrected several errors in the text, thanks to hDrummer for providing comments.

Source: https://habr.com/ru/post/239719/


All Articles