PHP Annotated – June 2020
Greetings everyone,
Please welcome the June edition of PHP Annotated!
PHP internals have been very active and here are 3 accepted and 6 new RFCs, including alternative syntax for attributes — @@
and why #[]
is better. There also has been some drama around renaming in the PHP world, and about PHP developers’ debugging practices. And as usual, a load of useful articles, tools, videos, podcasts, and more.
⚡️ News & Releases
- PHP turned 25 — Check out the timeline with the most important events in PHP history.
- PHP 7.4.7 — Among other things, this update fixes a bug with
yield from
. - PHP 7.3.19
- Composer 2.0.0-alpha1
- The State of Developer Ecosystem in 2020 — Links straight to the PHP section of the JetBrains developer survey.
65% of respondents pointed out that they use the ‘dump & die’ approach to debugging. So the tweet from the author of Xdebug, Derick Rethans, was always going to cause a strong reaction in the community:PHP developers that don't use Xdebug for debugging are amateurs.
— Derick Rethans 🔶 (@derickr) June 20, 2020
🐘 PHP Internals
- ✅ [RFC] Attribute Amendments — Attributes received a few additions: grouping capability
<<Attr1, Attr2>>
, renamingPhpAttribute
toAttribute
, validation, and the ability to add multiple identical attributes. - ✅ [RFC] Ensure correct signatures of magic methods — As for now, you can declare a magic method like this in a class:
class Foo { function __get(int $name): void { echo $name; } } (new Foo)->{42};
In PHP 8 however, signatures of magic methods will be validated and the code above will cause a compile-time error.
- ✅ [RFC] Make sorting stable — All standard sort functions in PHP (sort, usort, asort, etc.) starting with PHP 8.0 will be stable. This means that the original element order with the same values is guaranteed. In current versions, it is easy to find examples where this is not the case.
- ❌ [RFC] Opcache optimization without any caching — Declined.
- [RFC] Make constructors and destructors return void — In current PHP versions, you can return any values from constructors and destructors, for example:
class Test { public function __construct() { return 0; } } $test = new Test(); // this prints 0 echo $test->__construct();
Benas Seliuginas proposed to throw a
Deprecated
warning in such cases, and later in PHP 9.0 to remove this and generate aFatal Error
. - [RFC] Treat namespaced names as single token — Each element of the namespace is treated by the interpreter as a separate token. This is why there can be no keywords used in namespaces. For example,
namespace app\function { class Foo {} };
will fail with aParse Error
. Nikita Popov proposed to consider the entire namespace as a single token as this would minimize backward compatibility problems when introducing new keywords. - [RFC] Rename T_PAAMAYIM_NEKUDOTAYIM to T_DOUBLE_COLON — The token
::
in PHP is calledT_PAAMAYIM_NEKUDOTAYIM
— this fact was even pointed out as problem number one in the famous PHP Sadness list.
George Peter Banyard and Kalle Sommer Nielsen suggested renaming it. We’re not sure this makes sense, as the error messages always note::
.
Also, why remove a fun historical quirk? - [RFC] Shorter Attribute Syntax — Attributes have already been accepted for PHP 8, but many people do not like the syntax. Three options are being put to the vote:
<<Attr>>
(current) vs.@@Attr
vs.#[Attr]
. Brent Roоse had several convincing arguments for#[ ]
:
- It’s the same syntax as Rust, which is also a C-based language.
- It’s compatible with old code:
#[Attribute]
will be just ignored by PHP <=7.4 as a comment. @@
can be confused with the error suppress operator (example).<<>>
is also confusing, as it looks like bit-shift operators. In the future, it can be confused with generics that are likely to use the single angle brackets syntax<>
.
In the meantime,
@@
seems to be getting more votes. - [RFC] Change terminology to ExcludeList — The topic of renaming offensive terms has not been overlooked by the PHP world either. There have been heated discussions in the Internals.
In the PHP core, the change affects only one thing: the configuration directiveopcache.blacklist_filename
should be renamed toopcache.exclude_list_filename
.Many other PHP tools have already made changes in this regard: PHPUnit, Drupal, Xdebug, Yii, Composer (+ working with non-master Git branches).
There is also a discussion on set of rules for PHP_CodeSniffer to find offensive words.
- [RFC] Nullsafe operator — Instead of a bunch of nested conditions, Ilija Tovilo proposed to add the ability to refer to a property or method with a check for
null
:$country = $session?->user?->getAddress()?->country;
Instead of
$country = null; if ($session !== null) { $user = $session->user; if ($user !== null) { $address = $user->getAddress(); if ($address !== null) { $country = $address->country; } } }
- PHP 8.0 release schedule was updated — The feature freeze has been moved to August 4, and the final release is scheduled for November 26.
- You can try PHP 8 on 3v4l.org. Just check out the output in the php-master branch.
🛠 Tools
- beyondcode/expose — A tunneling service implemented in pure PHP on top of ReactPHP. An alternative to ngrok. You can run your own self-hosted server too. See more details about how it works.
- pestphp/pest — A tool that is built on top of PHPUnit and allows you to write tests in a simple elegant way. There is documentation and lots of videos. Inspired by facebook/jest.
- Moxio/sqlite-extended-api — The real demonstration of how FFI and lisachenko/z-engine can help: the package provides a couple of SQLite API methods that are not available in the standard PHP drivers.
- FriendsOfPHP/pickle — A PECL extensions manager that is compatible with Composer. This is the first update since 2015 and it finally seems to have a plan with Composer.
- doctrine/migrations 3.0.0 — A major update to the well-known package for handling DB migrations.
Symfony
- Symfony 5.1 was released.
- Symfony 5 certification is now available.
- In Symfony 6, configurations will be handled in usual PHP files instead of YAML or XML.
- dbu/snake-bundle — A snake game implemented on symfony/console.
- How much of a performance boost can you expect for a Symfony 5 app with PHP OPcache preloading?
- 10 Symfony testing tips.
- Protect Symfony app against the OWASP Top 10 threats.
Laravel
- spatie/laravel-cronless-schedule — A package for performing scheduled tasks without cron. It uses ReactPHP and timers under the hood. For more details check out the intro post.
- Laravel Debugbar vs. Telescope Toolbar
- Adding try/catch Laravel collections.
- Laravel package ecosystem statistics.
-
✨ In this thread I'll list tactics you can use to write cleaner code in Laravel.
As you use them repeatedly, you'll develop a sense for what's good code and what's bad code.
I'll also sprinkle some general Laravel code advice in between these tactics.
THREAD
— Samuel Stancl (@samuelstancl) June 16, 2020
Yii
Zend/Laminas
- Is Zend Framework Dead? — The Laminas project lead Matthew Weier O’Phinney answers this and a other questions.
- asgrim/mini-mezzio — Set up Mezzio applications even faster by using this package.
🌀 Async PHP
- badfarm/zanzara — An asynchronous framework for creating Telegram bots based on ReactPHP.
- simple-swoole/simps — Yet another Swoole-based framework. According to the benchmarks, it is the fastest one written in PHP.
- 📺 Video course on ReactPHP by Marcel Pociot.
💡 Misc
- Introducing the new Serverless LAMP stack — A post on the AWS blog about using serverless PHP, and a collection of links on the topic.
Also, Amazon’s official AWS Toolkit plugin is now available for PhpStorm. - Learn more about Constructor promotion in PHP 8.
- What are the top most used PHP functions in frameworks? — In Symfony it’s
sprintf()
, in Laravel it’sis_null()
. There are instructionson how to calculate similar stats for other frameworks. - On final classes in PHP.
- The fastest template engine for PHP.
- Unit test naming conventions.
📺 Videos
- PHP Russia 2020 Online videos.
- How to generate and view code coverage reports in PhpStorm using PHPUnit and Xdebug.
🔈 Podcasts
- Voices of the ElePHPant — Interview with Nuno Maduro.
- PHPUgly 194: Oversight
- PHP Internals News Podcast by Derick Rethans
• #58 — With Max Semenik on the accepted RFC non-capturing catches.
• #57 — With Ralph Schindler on his proposal about conditional return, break, and continue statements.
• #56 — With Dan Ackroyd on the newly added mixed pseudotype.
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