Meetup-Notes

Bordeaux Engineers Share and Talk #8 - Web technologies evolution

🕑 Estimated reading time: 8mn

Table of Contents

The PHP of today, not the one you remember about

By Thomas Calvet, PHP Engineer @ ekino

“PHP is dead”

If we talk to web developers about the situation of PHP, the general opinion is that the technology is dying, that the community gets older, etc. Bjarne Stroustrup, the creator of C++, once said that there are two types of languages: the ones that people complain about and the ones that nobody uses. Today, 78.9% of the web runs on PHP. Even though this share is on a downwards trend, PHP powers the actual majority of web properties.

PHP is not older than Java or JavaScript. Its evolution has been slower but it does its job, responds adequately to needs and supports among the biggest websites.

PHP is simple as in permissive, easy to learn but hard to master with quick feedback.
PHP is performant and responds to requirements, otherwise developers would have stopped using it.
PHP is mature with a developed ecosystem, enforceable Standards Recommendations (PSRs), libraries, frameworks, dependency management and Open Source.
PHP improves continuously and in the same direction as its community thanks to public RFCs.

PHP 7

PHP 7 has been a shock announcement at the time: thanks to a complete rewrite of the Zend Engine, PHP’s runtime environment, the language could run about three times faster while using significantly less memory. Moreover, each subsequent version incremented and added its own set of improvements to speed and memory usage and is still being worked on with PHP 7.4, which has been released on November 20th of 2019.

In 2020, PHP 8 will be released, marking the debut for an annual major release cycle bringing new areas for improvements to the technology and its ecosystem.

From the code perspective

PHP is becoming stricter with time. A few years ago, types could only be documented but not enforced by the language. Since PHP 7.0, efforts have been made to include a typing system in the language and allowing teams to make the switch progressively by adding support to sections of the language but making it optional. It started with function arguments, then return types, then optional arguments, void return types. An Object type, of which every other depends has been added along with two pseudo-types iterable and callable, which designate objects that can be iterated like arrays on or called like functions.

Class properties can now be typed, constants private to classes. Code can be made more robust, the feedback loop is reduced and errors detected earlier. Plus, since the types are defined by the development teams, PHP does not need to dynamically determine the type of every variable, since they can be inferred in the best case scenario, which leads to noticeable performance improvements.

Shortcuts

Syntactic sugar helps developers expressing ideas more efficiently. PHP 7.4 notably adds support for arrow functions, null coalescing ??, null coalescing assignment ??= and anonymous classes. Seasoned technicians will be delighted at the support for covariance and contravariance. Contravariance permits managing specific objects with broader selectors. For instance, given A extending B, if one implements a method using an instance of B, then a similar method using an instance of A, then the former can be replaced by the latter which is more generic.

The Foreign Function Interface or FFI opened a new way to write performant PHP in an unorthodox way, that is by writing C. This should be used in situations where performance is of utmost importance or if specific modules do not exist in PHP.

To reach new heights in performance, PHP 7.4 also introduces preloading as an experimental feature. PHP code does not change much from an execution to the next, unless a new version of an application is released. Thanks to opcode caching, files that are processed once get cached to avoid recompiling them every time, which would not be great for execution time. Nevertheless, whenever a file changes, it must be recompiled as soon as possible to avoid breaking applications. However, files usually change once in a while, during deployments. What if we could compile them the first time they are read and never after? That is exactly the promise of preloading. By reusing the result without checking for file changes, the performance can be massively improved. Symfony estimates a performance improvement of 30% to 50% for real workloads! (Source)

Finally, WeakReferences are arriving to PHP. They represent a way to link to an object without preventing its collection by a garbage collector. Combined with the future arrival of WeakMaps, planned for PHP 8, this should allow referencing a set of values while keeping tabs on memory efficiency. Useful when memory is precious.

Open exchange on the evolution of web technologies

By Antoine Brette, Java Developer @ ekino
By Jean-Baptiste Hembise, Java Developer @ ekino

Types

Many things look the same across languages today, even though slight differences persist in communities and ecosystems. Take types, for example. It is optional in TypeScript and PHP, where it is additionally dynamic and weak. PHP wants to change that with preloading, though. TypeScript type checking stops at the compilation step while PHP can also check types at runtime. Be it PHP or TypeScript, it has become good practice to strictly type. And with the deprecation of PHP 7.2, types are officially part of the language!

Kotlin proposes type inference, which can be seen as an evolution of strict type declaration in order to reduce its verbosity. Since Java 8, the language has evolved on a functional path, too. Thanks to the progress in hardware and compilation theory, it became possible to create technologies that allow writing less code and adding more sense at the same time.

null and undefined are handled peculiarly in Java; the objects that may not hold a value are wrapped in objects or sent to functions that will prevent system failures in case they do not hold a value. This shows this tendency to overwrap in Java, while Kotlin and TypeScript both have dedicated syntax to handle such cases.

Around the technology

Java uses a fast release train with a “major” release twice a year and an LTS every three years. PHP and JavaScript development is open to the community. Thanks to large organizations, their development has taken off exponentially over the last years. PHP’s release cycle is stable and usually followed. Nevertheless, there are projects using unmaintained versions out there. In Java, the situation got worse since the changes make it difficult to upgrade the code. Besides it is not always worth the investment. Even project Jigsaw, which deal was to bring modularity to Java 11, is not a common practice yet.

Core PHP’s community is reduced, possibly because of its core language, C. That makes the future of PHP difficult to envision, as some would like to create a version based off of C++, which would be called P++. Facebook developed their own flavor, Hack, and branched off of PHP a few years ago. In JavaScript, core contributors are plenty and governance is split across browser vendors and large users. Everything is structured and works relatively well. Micro-communities do not follow suit, though.

JavaScript reached its stability plateau which reduces the feeling of release fatigue linked to the frequent releases of the “Next Big Thing”. New tools and features are released less frequently now and technologies tend to converge, at least in terms of ideas. PHP is following the same path.

Big technologies are converging today while keeping a part of their personality.