1

PHP Annotated – October 2022

 1 year ago
source link: https://blog.jetbrains.com/phpstorm/2022/11/php-annotated-october-2022/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

News

PHP Annotated – October 2022

Roman Pronskiy
Roman Pronskiy November 2, 2022

PHP Annotated Monthly

Greetings everyone!

Welcome to the October installment of PHP Annotated, where we’ll catch up on the most exciting things that have happened in the PHP world over the last month, including curated news, articles, tools, and videos.

PHP Core

Most of the Core news is covered in detail in the PHP Core Roundup series from the PHP Foundation, so we’ll only mention it briefly:

  • RFC: json_validate #PHP 8.3
    Juan Carlos Morales proposed adding a new function called json_validate() that verifies whether a string contains a valid JSON. It saves memory when you don’t need to fully parse the string, but rather just check if it’s a JSON.
    var_dump(json_validate('{ "test": { "foo": "bar" } }')); // bool(true)
    var_dump(json_validate('{ "": "": "" } }')); // bool(false)
    var_dump(json_validate('{ "test": { "foo": "bar" } }'));  // bool(true)
    var_dump(json_validate('{ "": "": "" } }')); 		        // bool(false)
    
  • RFC: Improve unserialize() error handling #PHP 8.3
    Tim Düsterhus proposed throwing a new UnserializationFailedException when unserialization fails.

    This RFC caused a massive discussion on Twitter, and ultimately the new exception part was not accepted. Instead, the severity of the thrown error will now be increased from E_NOTICE to E_WARNING.

  • 📣 RFC: Randomizer Additions #PHP 8.3
    Tim Düsterhus and Joshua Rüsweg propose adding new “building block” methods to \Random\Randomizer. These methods would implement commonly useful operations that are either verbose or very hard to implement in user land.
    namespace Random;
    final class Randomizer {
    // […]
    public function getBytesFromAlphabet(string $alphabet, int $length): string {}
    public function nextFloat(): float {}
    public function getFloat(float $min, float $max): float {}
    namespace Random; 
    final class Randomizer {
        // […]
        public function getBytesFromAlphabet(string $alphabet, int $length): string {}
        public function nextFloat(): float {}
        public function getFloat(float $min, float $max): float {}
    }
    
  • 📣 RFC: Destructuring Coalesce #PHP 8.3
    Bob Weinand proposes adding an operator for default values in destructuring assignments.
    $input = 'key=value';
    [$key, $val ?? 'default value'] = explode('=', $input, 2);
    $input = 'key=value';
    [$key, $val ?? 'default value'] = explode('=', $input, 2);
    

    By the way, the defaults can now be appended to the array like so:

    [$key, $val] = explode('=', $input, 2) + [null, null]
    [$key, $val] = explode('=', $input, 2) + [null, null]
    

    Thanks for the tip, Sergii Shymko!

  • This was supposed to be a secret, but it got documented …

    The #PHP CLI server can handle multiple requests concurrently if you set PHP_CLI_SERVER_WORKERS since 7.4 …

    This has been various kinds of broken, but might be alright in the latest versions of PHP *for development*.

    — Joe Watkins (@krakjoe) October 26, 2022

Tools

  • dunglas/frankenphp – The modern PHP app server, written in Go and embedded in Caddy web server.
    Kevin Dunglas summarized this server’s main differences from RoadRunner:
  • krakjoe/parallel – A succinct parallel concurrency API for PHP 8+. The extension follows Golang’s philosophy on parallelism – “Do not communicate by sharing memory; instead, share memory by communicating” – and provides all the necessary bricks, like Channels, Events, and Futures.
  • cachewerk/relay – A Redis client like PhpRedis and Predis, but much faster because it is written as a PHP extension. The authors also provide Laravel, WordPress, and Magento integrations for caching.
  • Saeghe – A modern PHP package manager.
    PHP now has one more package manager! It uses GitHub links as dependencies. Additionally, it does not rely on PSR-autoloading, relying instead on a build stage.

    Competition is always a good thing!

  • composer-unused/composer-unused – A package that scans your code to reveal unused composer dependencies.
  • square/pjson – This library helps deserialize JSON into actual objects of custom-defined classes. It does so by using PHP 8’s attributes on class properties.
  • doctrine/collections 2.0.0 – A popular collections library that has received a major update adding more strict typing and native parameter and return types.
  • heiglandreas/holidayChecker – This package allows checking whether a given date is a holiday and is locale-aware.
  • Laragon – Another local dev environment tool – one that’s a portable, isolated, fast, and powerful alternative to XAMPP and similar solutions. Learn more in this post on PHP.Watch.
  • gacela-project/gacela – This package helps you build modular PHP applications, by splitting your project into different modules in a unified way. Heavily inspired by Spryker.

Symfony

Laravel

Videos

Conferences

Check out these upcoming big PHP gigs, and consider visiting or submitting a talk idea:

And if you are wondering when the next PHP meetup is, Tomas Votruba has got you covered with his lovely friendsofphp.org meetup aggregator. There is also a calendar on php.netEvents: November 2022.


That’s all for today, 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.

Subscribe
to PHP Annotated

Your JetBrains PhpStorm team
The Drive to Develop

php-annotated-roman.png

Roman Pronskiy

Product marketing manager for @PhpStorm, helped to launch @The PHP Foundation.

Twitter | GitHub

php-annotated-sergey.png

Sergey Panteleev

PHP 8.2 release manager, PHP Documentation maintainer.

Twitter | GitHub


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK