PHP Annotated – September 2020
Greetings everyone,
I hope you are all ready for September’s installment of PHP Annotated!
In it, we have the additional PHP 8 beta 4 release, the PHP community’s momentum with the generics discussion in Internals, and the Community Synergy Initiative. There are some interesting releases like Laravel 8, Composer 2.0 RC 1, and PoC for PHP support for GraalVM. And as usual, we’ve got a load of useful articles, tools, videos, and podcasts for you too.
⚡️ News & Releases
- PHP 8.0.0 Beta 4 — Additional unplanned beta release. It was added for stabilization of JIT and named arguments in the core, as well as reclassifying more notices and warnings.
The final release date is still set for November 26 though, and postponing it is not planned so far. The first release candidate is expected on October 1. - PHP 7.4.10, PHP 7.3.22
- The future of Zephir and Phalcon — Back in the days of PHP 5, there was a trend of developing frameworks as C-extensions to improve performance.
The most famous example is the Phalcon framework, which also had its own language Zephir.
Unfortunately, one of the top contributors to the project left. So the next release, Phalcon 5, is planned to be rewritten in pure PHP. - PHP: Community Synergy Initiative — Paul Dragoonis и Christoph Rumpel vowed to make the PHP community and ecosystem a better place.
There are a few significant problems outlined: unclear and outdated comments section in the documentation on php.net, lack of communication between the community and language maintainers, not enough transparency regarding what’s happening in the project besides the RFC documents for new features, and a lack of new people in the project.
To get things moving, the guys started an anonymous poll to learn more from the PHP folks worldwide: The PHP Community Survey 2020.
- PHP for GraalVM concept — The GraalVM project develops an alternative Java virtual machine with support for other languages. The experimental PHP implementation supports only a small subset of language features so far.
On a synthetic benchmark called Computer Language Benchmarks Game, it shows a x80 performance boost compared to PHP 7.4.
- The WordPress community discussed dropping support for old PHP versions. Judging by the answers of the project lead Matt Mullenweg, PHP 5.6 will be supported for a long time yet. The official statistics show that PHP ≤5.6 is used on 21.6% of WP installations.
A similar picture can be observed for MySQL adoption in WordPress: 65% use MySQL ≤5.6 while support for MySQL 5.5 is already over and 5.6 reaches its end-of-life in February 2021.
- Composer 2.0 RC 1 — Use
composer self-update --preview
to try.
🐘 PHP Internals
- ✅ [RFC] Shorter Attribute Syntax Change — The epic story of the syntax for attributes is finally over. The
#[Attribute]
option has won the vote.#[ ORM\Entity, ORM\Table("user") ] class User { #[ORM\Id, ORM\Column("integer"), ORM\GeneratedValue] private $id; #[ORM\Column("string", ORM\Column::UNIQUE)] #[Assert\Email(["message" => "The email '{{ value }}' is not a valid email."])] private $email; }
By the way, the previous syntax
@@Attr
did not support attribute grouping and therefore this feature was removed from PR. But since#[ ]
has an end marker, support for grouping has returned.// You can do this way #[ORM\Entity] #[ORM\Table("user")] // or this way #[ ORM\Entity, ORM\Table("user") ]
Learn more about attributes in this overview post.
- 🆕 [RFC] any() and all() on iterables — In this RFC Tyson Andre proposes to add two new functions to the standard lib:
any(iterable $input, ?callable $callback = null): bool
— executes the callback on each element and stops at the first that returnstrue
.
all(...)
— will only returntrue
if the callback returnstrue
for each element.Here is an example of it in action:
// Before $satisifes_predicate = false; foreach ($item_list as $item) { if (API::satisfiesCondition($item)) { $satisfies_predicate = true; break; } } if (!$satisfies_predicate) { throw new APIException("No matches found"); } // After if (!any($item_list, fn($item) => API::satisfiesCondition($item))) { throw new APIException("No matches found"); }
- 🆕 Runtime-erased generics proposal — Brent Roose, whom you might know from his posts on Laravel and PHP, came up with the idea of adding generics to PHP, but without any checks in the runtime.
Let’s say we have the following code with generics:
class Collection<T> { public function add(T $item) { ... } } $c = new Collection<Product>().
Static analyzers and IDEs will be able to parse it and perform analysis. However, the PHP interpreter is supposed to ignore generics and execute the code as follows:
class Collection { public function add(mixed $item) { ... } } $c = new Collection().
This is similar to how generics work in Hack language by default. And in Python, for example, almost all the information about types is removed in most cases and no popular interpreter validates types of arguments.
- 🆕 Observer API — PHP 8 will have an internal API to track when functions are entered or left. This is useful for extensions such as Xdebug, profilers, and APM solutions like New Relic, Tideways, and so on.
Find out more about the API in the 🔈 PHP Internals News podcast #68 with the authors Levi Morrison and Sammy K Powers.
🛠 Tools
- Pest 0.3 — A tool built on top of PHPUnit that allows you to write tests in a simpler way. Also, there is a plugin for PhpStorm, Pest IntelliJ.
- Codeception/Verify 2.0 — Assertions for PHPUnit and Codeception with a fluent interface.
- brick/money — A library for working with money values. Works even if there is no GMP or BCMath installed. Check out the comparison with moneyphp/money.
- bassim/super-expressive-php — The package allows you to describe regular expressions in an almost natural language through a fluent interface. There is also an alternative: VerbalExpressions/PHPVerbalExpressions.
- phpbench/phpbench 1.0.0-alpha1 — A very handy tool for benchmarking your code. In the new version, you can compare the results with the previous launches and use them on the CI for performance monitoring. Learn more.
- jawira/emoji-catalog — 3k+ emojis as PHP constants.
Symfony
- The “Symfony 5: The Fast Track” is available online in 12 languages.
- A Week of Symfony #716 (14-20 September 2020)
Laravel
- Laravel 8 released — Get a detailed overview 📺 on Laracasts,
- Laravel authentication ecosystem overview — Just in time with all the confusion around laravel/fortify.
- laravel/jetstream — Laravel 8 release features a skeleton application based on Livewire/Inertia.js..
- Common security mistakes in Laravel applications.
- Write code that interacts with the data in a predictable and safe way — A sample chapter from the book Laravel Beyond CRUD.
- 📺 Laravel Business — A YouTube channel with nice videos about the framework.
Yii
- yiisoft/auth — A fresh package from the Yii 3 family provides various authentication methods, a set of abstractions, and PSR-15 middleware for authentication.
- yiisoft/strings — Helpers for working with strings.
- Yii news 2020, issue 6.
🌀 Async PHP
- Building the next generation react/http PSR-15 adapter using krakjoe/parallel. In this case, the middlewares added via the adapter can be blocking because they are executed in separate threads in parallel.
- Using ReactPHP to consume data from an HTTP API.
💡 Misc
- Dialects in code: Part 1, Part 2 — How different people can use the same programming language in entirely different ways.
- 4 tips on refactoring in PHP.
- How unserialize() works on PHP and why it leads to vulnerabilities.
- Modern PHP security: Part 1 — Bug classes, Part 2 — Breaching and hardening the PHP engine.
- Speeding PHP with FFI.
- Turbocharged PHP Development with Xdebug, Docker & PhpStorm.
- On the impact of exceptions on performance — tl;dr: try/catch blocks have little effect, while throwing exceptions requires gathering a stack trace and creating an object, and as a result it takes longer. But in real applications, this will never be a bottleneck.
- Step-by-step instructions on how to contribute to opensource PHP package.
📺 Videos
- Tobias Nyholm’s talk about async-aws/aws, an async client for AWS services.
- PhpStorm Tips with Christoph Rumpel: More productive development with code snippets a.k.a. Live Templates.
- Nikita Popov interviews Nikolas Grekas about Symfony compatibility with PHP 8.
- Using Xdebug’s Function Trace functionality for logging every function call with all arguments and return values. And one more video on how to use Xdebug profiler.
🔈 Podcasts
- PHP Internals News #67 — Derick Rethans talks to himself about the new
match
expression. - Voices of the ElePHPant interviews:
• With Olatunbosun Egberinde
• With Matthew Setter
• With Larry Garfield
And last but not least, check out the new PHP 8 logo!
And a joker ConFoo elePHPant with PHP 8 logo is available for preorder (minimum 6 pc.).
Thanks for reading!
If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post or send me a tweet.
Your JetBrains PhpStorm team
The Drive to Develop