PHP Annotated – February 2020
Greetings everyone,
It’s time for the February edition of PHP Annotated! This edition includes 4 new RFCs from PHP Internals and research results on Generics in PHP. We also cover PHPUnit 9 and other releases, articles on Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!
⚡️ News & Releases
- PhpStorm 2020.1 EAP started — We’ve already rolled out composer.json support, code coverage with PCOV, new Commit tool window to work with VCS, and a bunch of other improvements.
You can follow us on Twitter @phpstorm and subscribe to our YouTube channel JetBrainsTV to get fresh updates as we’ve launched a new video series, What’s Coming in PhpStorm 2020.1 and 📺 Episode 1 is already out. - Based on the voting results the new Core Committee will include Korvin Szanto, Enrico Zimuel, Chris Tankersley, and Massimiliano Arione. Buster Neece is the new secretary.
🐘 PHP Internals
- [RFC] Allow function calls in constant expressions — In the current PHP versions, you can only use literals, and operations in constant expressions. This RFC proposes to allow global functions calls in constant declarations, default values of static properties, static variables, and default values of function parameters.
class MyClass { const VALUES = [1, 0]; const C1 = count(self::VALUES); public static $p = count(self::VALUES); public function foo($param = count(self::VALUES)) { static $bar = count(self::VALUES); } }
- [RFC] __toArray() — This onу proposes to add a new magic method
__toArray()
, which will work similarly to__toString()
, i.e. will be called on explicit type casting to array, or when an object is passed as an argument to a function with an array parameter declaration, or when it’s returned from a function with its return type specified as an array.class Person { protected $name; protected $email; public function __toArray() { return [ 'name' => $this->name, 'email' => $this->email, ]; } } $person = new Person('John Doe', 'j.doe@example.com'); $personArray = (array) $person; // Calls __toArray() function foo(array $person) { var_dump($person); // Array here } function bar(Person $person): array { return $person; } var_dump(bar($person)); // and here it's an array
- [RFC] Userspace operator overloading — The proposal to add operator overloading is still in draft status, but is actively discussed in Internals. Meanwhile, you can try operator overloading in PHP 7.4 with FFI based on lisachenko/z-engine.
- [RFC] Validation for abstract trait methods — Currently, signatures of implementation for abstract methods from traits are not validated. For example, this code now works without errors:
trait T { abstract public function test(int $x); } class C { use T; // It works now, but it shouldn't because of a type mismatch public function test(string $x) {} }
It’s proposed to correct this behavior.
The patch was published as a pull-request, but it contains a backward incompatibility, that requires to pass the RFC-process: if then current code has an incorrect implementation of the method from a trait, the proposed change will cause an error. - [RFC] Server-Side Request and Response Objects v2 — The RFC proposes to replace superglobal arrays such as
$_GET
,$_POST
,$_SERVER
, etc., with a ServerRequest class, and ServerResponse instead ofheader()
calls and sending content. - Generics in PHP — Recently, Nikita Popov has been working on a study of the possibility of adding generics to PHP. In short, according to Nikita, there are some serious difficulties, and he is not sure yet if adding complete generics to PHP is a good idea.
There is a pull request with a prototype implementation and all the problems and open questions are detailed here: https://github.com/PHPGenerics/php-generics-rfc/issues/45. - php/doc-en — English documentation is now editable via pull-requests on GitHub instead of old edit.php.net.
🛠 Tools
- PHPUnit 9 — This release requires PHP 7.3+ and uses modern PHP features. It also has some backward-incompatible changes. Learn more in the migration instruction.
- cycle/orm 1.2 — An ORM that can be used either as DataMapper or as ActiveRecord. In the latest release, the performance was improved by 33% and judging by these benchmarks, it is now one of the fastest ORMs.
- lisachenko/z-engine — An experimental library that allows accessing the internal structures of PHP itself using FFI. There are examples of using it to implement immutable objects or modifying AST on a fly.
- salsify/jsonstreamingparser — A JSON streaming parser for working with large files.
- spatie/docker — This package provides a way to start docker containers and execute commands on them. Check the blog post to learn more.
- symfony/polyfill-php80 — A PHP 8.0 polyfill.
- BenMorel/weakmap-polyfill — A polyfill for WeakMap for PHP 7.4.
- paratestphp/paratest — A tool that helps parallelize PHPUnit tests. Compatible with PHPUnit 9.
Symfony
- A story of finding performance issues in a Symfony application, part 2.
- Grant on permissions, not roles.
- A Week of Symfony #684 (February 3-9, 2020).
Laravel
- pavel-mironchik/laravel-backup-panel — A web-interface for spatie/laravel-backup. Allows managing backups in a browser.
- avto-dev/roadrunner-laravel — A new version of the RoadRunner worker for Laravel. Now by default it does not re-create the application instance, and can be extended using the event system of the framework.
- laravelpackage.com — A detailed guide for creating Laravel packages.
- On authentication and laravel/airlock.
- Containerizing Laravel 6 application for development with Docker Compose and Ubuntu 18.04.
- How to use mixins in Laravel.
- Laravel beyond CRUD: 09. Test factories.
- 📺 Tips for simplifying Laravel controllers.
- 🔈 Taylor’s podcast: Laravel Snippet #22 — Laracon Online, Inertia.js, Livewire, SPAs, Reviewing The Day.
Zend/Laminas
- The last post in Zend Framework blog – It’s now all Laminas.
🌀 Async PHP
- 📺 Interview with Marc Morera, an author of DriftPHP, about asynchronous PHP, DriftPHP and ReactPHP.
- driftphp/awesome-reactphp — A curated list of resources for ReactPHP.
💡 Misc
- PHP in 2020 — An overview of the language and ecosystem state.
- New in PHP 8.
- Enums without enums in PHP — Imitating enums with anonymous classes.
- Type matching in PHP — Implementing the match construct from Rust on PHP with arrow functions.
- My PhpStorm settings after 8 years of use.
- Modern PHPDoc Annotations for arrays — In PhpStorm it recommends using the deep-assoc-completion plugin.
- Benchmark of PHP 7.4 preloading on a Symfony application.
- A history of optimizing the performance of a monolith app with Blackfire.io.
- On aspect-oriented programming on PHP using Go!AOP.
- Redux in 30 lines of PHP.
- An anonymous researcher published exploits that reveal vulnerabilities in processing disable_functions ini-option of PHP. Learn more in an interesting analysis of this vulnerability class.
📺 Videos
- 📺 Laracon AU 2019 videos.
- 📺 Scotland PHP 2019 videos.
- 📺 PHPKonf 2019 videos — With Midori Koçak’s talk on how to have your idea accepted to PHP as a newbie.
- 📺 Full course on Event Sourcing.
- 📺 Snapshot Testing in PHPUnit with spatie/phpunit-snapshot-assertions.
🔈 Podcasts
- 🔈 The Undercover ElePHPant #6 — On the pros and cons of the shared-nothing architecture of PHP and on serverless with Mathieu Napoli.
- 🔈 The Undercover ElePHPant #7 — With Jordi Boggiano on logging in production and best practices of logging in general.
- 🔈 PHP Internals News #38 — On preloading and WeakMaps with Nikita Popov. Now with text script.
- 🔈 PHP Internals News #39 — On the Stringable interface with с Nicolas Grekas.
Thanks for reading!
If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post, or tweet me.
Your JetBrains PhpStorm Team
The Drive to Develop