🕑 Estimated reading time: 8mn
By Thomas Calvet, PHP Engineer @ ekino
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 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 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.
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
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.
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.
By Antoine Brette, Java Developer @ ekino
By Jean-Baptiste Hembise, Java Developer @ ekino
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.
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.
Big technologies are converging today while keeping a part of their personality.