Quantcast
Channel: PHP Annotated Monthly : The PhpStorm Blog | The JetBrains Blog
Viewing all 104 articles
Browse latest View live

PHP Annotated – July 2019

$
0
0

php_annotated

Greetings everyone,

In our July’s edition of PHP Annotated, you can read about the latest on the PHP 7.4.0 alpha 3 release, ReactPHP 1.0 LTS, new proposals from PHP Internals, such as the Strict operators directive, as well as links for Laravel and Symfony, useful tools, videos, and a whole lot more!

(more…)


PHP Annotated – August 2019

$
0
0

php_annotated

Greetings everyone,

In our August edition of PHP Annotated, read about the future of PHP. Is it P++ or PHP2020? Get the latest on PHP 7.4.0 beta 2, Slim 4, and other releases. We cover Laracon US, as well as share other links for Laravel and Symfony, useful tools, videos, and a whole lot more!
(more…)

PHP Annotated – September 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our September edition of PHP Annotated! Get the latest on PHP 7.4.0 RC 1, Laravel 6, Monolog 2, and other releases. There are loads of insights from PHP Internals, including Union Types RFC, plus we’ll share links for Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!
(more…)

PHP Annotated – October 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our October edition of PHP Annotated! Get the latest on PHP 7.4.0 RC 3, GitHub dependency graph support for PHP, upgrading PSR standards, RFCs from PHP Internals, and the Coordinating PHP project. We’ll share links for Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!
(more…)

PHP Annotated – November 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our November edition of PHP Annotated! Get the latest on PHP 7.4.0 RC 5, Xdebug 2.8.0, a critical vulnerability in PHP-FPM, and news from PHP Internals. There are also links for Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!
(more…)

PHP Annotated – December 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our December edition of PHP Annotated! Read about the latest releases PHP 7.4, Symfony 4.4 and 5.0, Xdebug 2.9, news from PHP Internals, articles on Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!
(more…)

PHP Annotated – January 2020

$
0
0

php_annotated

Greetings everyone,

It’s time for 2020’s first edition of PHP Annotated! This edition includes 4 new RFCs from PHP Internals and a few interesting updates for PHP 8 in pull-requests. We’ll catch up on the fresh releases from the end of 2019: Codeception 4.0, Phalcon 4.0, CakePHP 4.0. We’ve also got articles on Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!
(more…)

PHP Annotated – February 2020

$
0
0

php_annotated

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!
(more…)


PHP Annotated – March 2020

$
0
0

php_annotated

Greetings everyone,

We’re pleased to present the March edition of PHP Annotated. It includes 4 new RFCs from PHP Internals, including Attributes v2 and a PHP language evolution proposal. It also covers Laravel 7, CodeIgniter 4, and other releases, as well as articles on Laravel and Symfony, useful tools, videos, podcasts, and plenty of other exciting posts!
(more…)

PHP Annotated – April 2020

$
0
0

php_annotated

Greetings everyone,

This April edition of PHP Annotated overviews 10 new RFCs from PHP Internals, Composer 2.0 alpha, and other releases, as well as articles on Laravel and Symfony, best practices, useful tools, videos, and podcasts.
(more…)

PHP Annotated – June 2020

$
0
0

php_annotated

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.
(more…)

PHP Annotated – August 2020

$
0
0

PHP Annotated Monthly

Greetings everyone,

Please welcome the August installment of PHP Annotated!

PHP 8 has reached feature freeze and received a few last big additions: the nullsafe operator, named arguments, and saner string to number comparison. The syntax for attributes, though, has not yet been decided. Read the full story behind the attributes from the initial proposal to the latest revote and the battle between #[] and @[]. And as usual, we’ve got a load of useful articles, tools, videos, and podcasts for you in this issue.

(more…)

PHP Annotated – August 2020

$
0
0

PHP Annotated Monthly

Greetings everyone,

Please welcome the August installment of PHP Annotated!

PHP 8 has reached feature freeze and received a few last big additions: the nullsafe operator, named arguments, and saner string to number comparison. The syntax for attributes, though, has not yet been decided. Read the full story behind the attributes from the initial proposal to the latest revote and the battle between #[] and @[]. And as usual, we’ve got a load of useful articles, tools, videos, and podcasts for you in this issue.

(more…)

PHP Annotated – September 2020

$
0
0

PHP Annotated Monthly

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.

(more…)

PHP Annotated – October 2020

$
0
0

PHP Annotated Monthly

Greetings everyone!

In our October edition of PHP Annotated you can read about the upcoming PHP 8, Xdebug 3 beta, short functions, and multiline arrow functions proposals in Internals. And as usual, we’ve got a load of useful articles, tools, videos, and podcasts to tell you about, too.

(more…)


PHP Annotated – January 2021

$
0
0

PHP Annotated Monthly

Greetings everyone,

In this edition of PHP Annotated, read about the top PHP news from the year so far. These include PHP 8.0.1 and other releases, fibers for async PHP, Enums, first native attributes, and other proposals for PHP 8.1. And as usual, we’ve got a load of articles, tools, videos, and streams, carefully selected for you.

(more…)

PHP Annotated – February 2021

$
0
0

PHP Annotated Monthly

Greetings everyone,

In this edition of PHP Annotated, you can read about the latest release of PHP, updates of PSR standards, and the new RFC proposals. As usual, we’ve curated a collection of PHP-related articles, tools, videos, and streams to share with you.

(more…)

PHP Annotated – March 2021

$
0
0

PHP Annotated Monthly

Greetings everyone,

In this edition of PHP Annotated, read about the latest proposals for PHP 8.1, releases of xdebug.cloud, RoadRunner 2.0, and the newly proposed PSR ClockInterface standard. And as usual, we’ve got a load of articles, tools, videos, and streams carefully selected for you.

⚡ News

🐘 PHP Internals

  • ✅ [RFC] Enumerations
    PHP 8.1 will have long-awaited enums!
    enum RfcStatus {
        case Draft;
        case UnderDiscussion;
        case Accepted;
    }
    
    function setRfcStatus(RfcStatus $status) :void {
        // ...
    }
    
    setRFCStatus(RfcStatus::Accepted); // Ок
    setRFCStatus('Draft');             // TypeError
    
    If you like the enums feature, please consider sponsoring the authors of this RFC: Ilija Tovilo and Larry Garfield.

    Read more about enums in Brent Roose’s article and some more on php.watch.

    Symfony has already opened tickets to add enums support.
  • ✅ [RFC] Deprecate passing null to non-nullable arguments of internal functions
    In the current versions of PHP, standard functions can accept null as an argument when the parameter is not nullable without any errors.

    To fix this inconsistency, in PHP 8.1 built-in functions will throw a Deprecation notice, and in PHP 9 they will throw a TypeError. For example, str_contains("", null). 3v4l.org/OVoa0A.
  • ✅ [RFC] Array unpacking with string keys
    Unpacking arrays will work consistently in PHP 8.1, including arrays with string keys:
    $array1 = ['a' => 'apple', 'p' => 'pear'];
    $array2 = ['b' => 'banana', 'o' => 'orange'];
    $array = [...$array1, ...$array2];
    // The same as:
    $array = array_merge($array1, $array2);
    
  • [RFC] PHP\iterable\any() and all() on iterables
    The proposal to add any() and all() functions for iterators did not pass the vote.
  • [RFC] var_representation() : readable alternative to var_export()
    The idea to add an alternative for var_export also did not find support, so for now we can use a userland alternative brick/varexporter.
  • 🗳 [RFC] Fibers
    Voting on Fibers has started. In short: this is a small but important improvement to generators that endeavors to make writing asynchronous PHP code easier. For example, like this:

    The Scheduler was removed from the RFC, so the Fiber API now provides the bare minimum and is similar to the resembling feature in Ruby.

    There were some reasonable arguments against the proposal from Swoole maintainers. As well as from Joe Watkins, the author of krakjoe/parallel extension.

    Yet, fibers seem to be a real step in the direction of asynchronous capabilities, which does not contradict either Swoole or parallel.

  • 🗳 [RFC] mysqli bind in execute
    Kamil Tekiela continues the initiative to improve mysqli. This RFC proposes adding a new optional parameter to mysqli_stmt::execute() that will take an array of values and bind them automatically. Currently, you have to make a separate call to mysqli_stmt::bind_param(), which only accepts variables passed by reference.
  • [RFC] New in initializers
    In the current versions of PHP, initializers such as the default values of properties, parameters, and constants can only have constant values.

    When non-constant values are needed, properties can be initialized in a constructor, and arguments can be initialized in the method’s body. With constants, there are no such options at all.

    Nikita Popov proposes to make it possible to use objects as default values for properties, parameters, and any constants and static variables.

    static $x = new Foo();
    
    const C = new Foo();
    
    class Bar
    {
        public const CONSTANT = new Foo();
        public static Foo $staticProperty = new Foo();
    
        #[Assert\All([new Assert\Uuid()])]
        public array $uuids = [];
    
        public function __construct(
            private Logger $logger = new NullLogger()
        ) {}
    }
    
    function test($param = new Foo()) {}
    

    For now, the proposal is limited to the new operator, but the implementation allows extending support for other expressions in the future.

    An additional bonus (or an intention? 🤔) is that objects will be allowed in the attributes. That solves the problem with nested attributes.
  • [RFC] CachedIterable (rewindable, allows any key&repeating keys)
    Tyson Andre suggests adding a caching iterator. It stores the state of an iterator and internally contains immutable copies of its keys and values.
  • [RFC] Namespaces in bundled PHP extensions
    All classes and functions provided by bundled PHP extensions are currently located in the global namespace (with one exception).

    This RFC proposes a convention on using namespaces with bundled extensions. Basically, the extension name should be used as a namespace and no PHP prefix is needed. For example, OpenSSLCertificate can become OpenSSL\Certificate.

    So far, however, this only applies to new symbols added, and the migration of existing functions and classes is not affected by this RFC. But the examples show possible future transformations:
    str_contains() -> String\contains()
    in_array() -> Array\contains().
  • [RFC] noreturn type
    The authors of Psalm and PHPStan suggest adding a new type to PHP – noreturn.

    The authors of Psalm and PHPStan suggest adding a new type to PHP – noreturn. This would be a bottom type indicating that a function either always throws an exception or terminates execution, i.e. calls exit(), die(), trigger_error().
    function redirect(string $uri): noreturn {
        header('Location: ' . $uri);
        exit();
    }
    
    function redirectToLoginPage(): noreturn {
        redirect('/login');
    }
    

    There is a similar type in Hack and in Python, and it has been used in Psalm, PHPStan, and also in PhpStorm as an attribute #[NoReturn] or via an exitPoint() in .phpstormmeta.php.

phpstorm PhpStorm

🛠 Tools

Symfony

Laravel

Yii

💡 Misc

📺 Videos

🔈 Podcasts

  • php[architect] podcast #50 – Discussed the Mezzio framework, functional programming, and software dependency security.
  • PHP Ugly podcast:
    #227: – Math is Hard.
    #226: – Help Wanted, PHP Release Manager.
  • PHP Internals News podcast:
    #75 – With Nikita Popov on deprecating null, array unpacking, restrict globals usage, and phase out serializable.
    #76 – Another one with Nikita Popov about restricting the use of globals, and phasing out serializable.
    #77 – With David Gebler about the fsync() function added to PHP 8.1.
    #78 – With Andreas Heigl on moving PHP documentation to Git.

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 — May 2021

$
0
0

PHP Annotated Monthly
Greetings everyone!

PHP 8.0 is gaining momentum and adoption is increasing, as evidenced by Composer’s statistics.

Meanwhile, PHP internals have accepted a bunch of changes for PHP 8.1, including a new never type and namespaces in bundled PHP extensions, and some features that will be deprecated.

The PHP 8.1 release managers have been selected, and there are several interesting proposals under discussion, including property accessors, pure intersection types, and final constants.

Read more about this news in the May edition of PHP Annotated. As usual, we’ve carefully selected a collection of articles, tools, videos, and streams for you.

⚡ News

  • PHP Versions Stats – 2021.1

    The traditional compilation of statistics based on the data that Composer sends when it connects to packagist.org:

    • PHP 7.4: 45.92% (+3.31)
    • PHP 7.3: 21.30% (-5.75)
    • PHP 7.2: 12.89% (-2.39)
    • PHP 8.0: 9.44% (+9.17)
    • PHP 7.1: 5.21% (-2.24)
  • PHP is available on Google Cloud Functions

    Google Cloud’s serverless platform now natively supports PHP. With GoogleCloudPlatform/functions-framework-php/ you can run functions in a PHP 7.4-based runtime.

    There are a few more details in the discussion on GitHub in the Symfony repository. Symfony 5.3 should run on GCF smoothly, thanks to the Runtime component. You just need to install php-runtime/google-cloud.

  • Composer Command Injection Vulnerability

    The vulnerability in Composer only affects systems that have Mercurial installed. However, it is worth immediately updating to versions 2.0.13 and 1.10.22, which contain fixes. Check out a more detailed technical analysis of the vulnerability.

  • Follow up on git.php.net attack

    Attackers pushed two commits to the PHP source on behalf of Rasmus Lerdorf and Nikita Popov. The problem was quickly detected and solved. The malicious code did not get to users.

    As it turned out, the git.php.net server allowed commits via HTTPS and used digest authentication, which accepts md5 hash as a secret. The hash database of all the contributors was obtained by the attackers from master.php.net, which was probably the server that was originally compromised.

    As a result, all development has been fully moved to GitHub, which makes life easier for language developers.

  • PHP 7.4.19, PHP 8.0.6 – With a fix in PDO_pgsql.

🐘 PHP Internals

  • ✅ [RFC] never type

    PHP 8.1 will have a new type for returned values: never.

    A function or method declared with the never type indicates that it will never return a value, and it either throws an exception or terminates with a call of type die(), exit(), trigger_error().

    It is an empty bottom type and is a subtype of all other types, and there are similar types in Python, Rust, Kotlin, and TypeScript. This type improves static analysis.

    function redirect(string $uri): noreturn {
        header('Location: ' . $uri);
        exit();
    }
    
    function redirectToLoginPage(): noreturn {
        redirect('/login');
    }

    You can find more details on PHP.Watch or listen to the PHP Internals News podcast with Matt Brown and Ondřej Mirtes.
  • ✅ [RFC] Deprecate implicit non-integer-compatible float to int conversions

    In PHP 8.1, an E_DEPRECATED notice will be thrown when float is converted into int and fractional part is lost. Later, in PHP 9.0, this will cause a TypeError.

    function acceptInt(int $i) {
            var_dump($i);
    }
    acceptInt(3.1415);
    
    > int(3) // Deprecation notice

    Learn more from the 🔈 PHP Internals News podcast #83 with George Peter Banyard.
  • ✅ [RFC] Phasing out Serializable

    In PHP 8.1 the Serializable interface will be deprecated. A deprecation notice will be thrown when the class uses only this interface, that is, if the class does not additionally have the new magic methods __serialize() and __unserialize().

  • ✅ [RFC] Namespaces in bundled PHP extensions

    This marks a small step towards cleaner PHP! New symbols (classes, interfaces, etc.) in extensions will now have to use namespaces.

    Here’s an example. The resource type is de-facto obsolete in PHP, and all existing resources are slowly being migrated to objects. In PHP 8.1 some resources will be replaced with the following namespaced classes:

    IMAPConnection -> IMAP\Connection
    FTPConnection -> FTP\Connection
    LDAP -> LDAP\Connection
    LDAPResult -> LDAP\Result
    LDAPResultEntry -> LDAP\ResultEntry
    PgSql -> PgSql\Connection
    PgSqlResult -> PgSql\Result
    PgSqlLob -> PgSql\Lob
  • ✅ [RFC] Add return type declarations for internal methods

    Most of the built-in methods in PHP 8.0 have received parameters and return type declarations. In some cases, however, this could not be done, like for the return values of public non-final methods. The problem is that they can be overridden in user code.

    Here is an example to illustrate the problem

    class SomeStandardClass
    {
        public function method(): int {}
    }
    
    class UserClass extends SomeStandardClass
    {
        public function method() {}
    }
    
    // Fatal error: Declaration of UserClass::method() must be compatible with SomeStandardClass::method()
    

    There will now be a gradual migration for such cases. In PHP 8.1, all internal methods will also get the missing types. If they are overridden in user code, a Deprecation notice will be thrown.

    class MyDateTime extends DateTime
    {
        public function modify(string $modifier) { return false; }
    }
    
    // Deprecated: Declaration of MyDateTime::modify(string $modifier) should be compatible with DateTime::modify(string $modifier): DateTime|false
    
  • Release managers for PHP 8.1 have been selected

    There will be three managers this time around: the experienced Joe Watkins (pthreads, parallel, pcov), and two newcomers, Patrick Allaert (blackfire.io) and Ben Ramsey (ramsey/uuid). Check PHP Internals News podcast #84 with Ben and Patrick.


    New proposals for PHP 8.1:

  • [RFC] Partial Function Application

    Partial function application (partial functions) is when only some arguments are bound on function call, and the others remain as parameters to be passed later.

    For example, here is a full function:

    function whole($one, $two) {
        /* ... */
    }

    And here’s a partial one based on it:
    $partial = whole(?, 2);

    In this case, the partial signature will look like this:
    function($one) {
        /* ... */
    }

    Why is this needed?

    Firstly, you can now get a reference to any function or method and pass it wherever Callable is expected. For example, you could do this

    array_map(Something::toString(?), [1, 2, 3]);
    array_map(strval(?), [1, 2, 3]);
    
    // instead of
    array_map([Something::class, 'toString'], [1, 2, 3])
    array_map('strval', [1, 2, 3]);

    And secondly, as a consequence, it will be possible to implement the pipe operator |>:
    $result = "Hello World"
        |> htmlentities(?)
        |> explode(?);

    See it in action at 3v4l.org.

    Thanks to Larry Garfield, Joe Watkins, Levi Morrison, and Paul Crovella for the RFC and the implementation.

  • [RFC] Property Accessors

    Nikita has finalized the implementation of the property accessors, and the proposal is now officially under discussion.

    The bottom line is that traditional getters and setters are not convenient to use, and the magic methods __get and __set are not specific. The new accessors are meant to fix these issues.

    The syntax is inspired by C#:

    class Foo {
        public $prop {
            get { /* ... */ }
            set { /* ... */ }
        }
    }
    

    You can use them to implement read-only properties:
    class User {
        public string $name { get; }
    
        public function __construct(string $name) {
            $this->name = $name;
        }
    }
    

    And you can specify asymmetric access, i.e. make them public or private separately for reading and writing:
    class User {
        public string $name { get; private set; }
    
        ...
    }
    

    Or you can use them as full-fledged methods for validation or other actions:
    class Foo {
        public int $bar {
            get {
                error_log('Getting $bar');
                return $this->bar;
            }
            set {
                assert($bar > 42);
                $this->bar = $bar;
            }
        }
    }
    
  • [RFC] Pure intersection types

    Union types were added in PHP 8.0, and this RFC proposes to add intersection types.

    The syntax is TypeA&TypeB, and it means that the variable must be both instanceof TypeA and instanceof TypeB.

    Details

    class A {
        private Traversable&Countable $countableIterator;
    
        public function setIterator(Traversable&Countable $countableIterator): void {
            $this->countableIterator = $countableIterator;
        }
    
        public function getIterator(): Traversable&Countable {
            return $this->countableIterator;
        }
    }
    

    The proposal is called “pure intersection types” because combinations with union types are not supported and are being left for future consideration. Aliases for complex types are also being left for the future.

  • [RFC] Deprecate ticks

    There is a tick mechanism in PHP: declare(ticks=1). It was originally needed to track pcntl signals. Now you can use pcntl_signal() and pcntl_async_signals() for this, which is why there’s been a suggestion to deprecate ticks in PHP 8.1 and remove them completely in PHP 9.

  • [RFC] Final class constants

    The author of this RFC proposes a final modifier for constants, so that they cannot be overridden in child classes.

    Details

    class Foo
    {
        final public const X = "foo";
    }
    
    class Bar extends Foo
    {
        public const X = "bar";
    }
    
    // Fatal error: Bar::X cannot override final constant Foo::X
    

    Fun fact from RFC: constants in interfaces are already final.

  • A couple more links for those who would like to start contributing to PHP source:

🛠 Tools

Symfony

Laravel

Yii

PhpStorm

💡 Misc

📺 Videos

🔈 Podcasts

🙌 Community

  • PHP’s bus factor is 2 – Joe Watkins says that only two people know enough about the PHP source, so we should consider this when thinking about adding new features to PHP. He also says that we need more developers working on the core.

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 — August 2021

$
0
0

PHP Annotated Monthly

Greetings everyone!
PHP 8.1 has reached the second beta and the list of changes has been finalized. The final piece left to decide on is the nullability of intersection types, which is being voted on right now.

Meanwhile, PHP internals are already discussing features for the next release. Read on to learn about the first two RFCs for PHP 8.2, which is coming in 2022.

As PHP 8.1 is going to have fibers, two popular async frameworks for PHP have agreed to join forces and work together on shared abstraction.

You can read more about this news in the August edition of PHP Annotated. As usual, we’ve carefully selected a collection of articles, tools, videos, and streams for you.

⚡ News

  • PHP 8.1.0, Beta 2

    The beta releases signal the end of the active development phase of PHP 8.1, which means that the list of new features and changes can be considered final (with the exception of nullable intersection types). The third and final beta is expected August 19.


    Image by Peter Kokot.

    So what’s coming in PHP 8.1?
    Here is a shortlist of the most notable changes:

    • Enums (RFC).
    • First-class callables (RFC).
    • Readonly properties (RFC).
    • New operator in initializers (RFC).
    • Brand new never type for return values (RFC).
    • Fibers (RFC).
    • Final constants in classes (RFC).
    • Spread operator supporting string array keys (RFC).
    • Deprecation of implicit non-integer-compatible float to int conversions (RFC).
    • Deprecation of serializable interfaces (RFC).
    • Explicit octal notation with the 0o prefix (RFC).
    • Restricted usage of $GLOBALS (RFC).

    If you’d like to learn more, check out this awesome compilation of PHP 8.1 “before” and “after” examples.

    There is also a 10-day newsletter from Brent Roose: The Road to PHP 8.1.

    And a full description of all the changes is available on PHP.Watch: php.watch/versions/8.1.

    PHP.Watch also has a post on Directory Uploads in PHP 8.1 – In PHP 8.1 the $_FILES array will contain a full_path section with directory structure paths from the user. This is needed to support directory uploading.

  • ReactPHP and AmpPHP join forces

    With the addition of fibers in PHP 8.1, asynchronous PHP code may be a little easier and prettier. The maintainers of two popular libraries for asynchronous PHP have announced the RevoltPHP project. They plan to make a common event loop and implement shared abstraction over fibers.

  • PhpStorm 2021.2 has been released

    Check out this blog post that contains all the details about generics support, enums, array shapes, and everything else that is being introduced in this release.

  • PHP 7.4.22, PHP 8.0.9

    Security and bugfix updates for current branches.

🐘 PHP Internals

  • [RFC] Nullable Intersection types

    Shortly after the adoption of the RFC on type intersections, a comment was posted by Nikolas Grekas (Symfony core). He said that without the ability to make them nullable, the intersections are much less interesting.

    Technically, the PHP 8.1 branch is already frozen, but the PHP team decided to make an exception for this proposal.

    class Foo
    {
        public (X&Y)|null $bar;
    
        function setBar((X&Y)|null $bar = null): (X&Y)|null
        {
            return $this->bar = $bar;
        }
    }
    

    Syntax choice is also put to a vote: ?X&Y or (X&Y)|null.
  • [RFC] Unwrap reference after foreach

    In the current versions of PHP, there is no dedicated scoping for the foreach loop. This has a very counterintuitive consequence: the reference to the $value and the last element of the array remain even after the foreach loop ends.

    The problem is easily illustrated by this example:

    $array = [0, 1, 2];
    foreach ($array as &$value) { /* ... */ }
    // without calling unset($value),
    // $value still points to the last element: $array[2]
    
    foreach ($array as $value) {
    // $array[2] will be updated each time with the values of $array
    }
    var_dump($array);
    
    // Before RFC:
    >
    array(3) {
        [0] => int(0)
        [1] => int(1)
        [2] => &int(1)
    }
    
    // After RFC:
    > array(3) {
        [0] => int(0)
        [1] => int(1)
        [2] => int(2)
    }
    

    This RFC proposes a fix for this logically correct, but buggy-looking, behavior. After the foreach loop, the reference to $value will be removed.
  • [RFC] Never For Parameter Types

    In PHP 8.1 there will be a new type, never, for return values. For PHP 8.2, there is already a proposal to use never as the type for parameters.

    The author of the RFC, Jordan LeDoux, thinks that never will be useful in abstract classes and interfaces. You could use it to specify that the parameter must be typed in some way.

    This could help to mimic the behavior of generics. However, you will still have to resort to the type descriptions in PHPDoc for static analyzers and PhpStorm.

    interface CollectionInterface {
        public function add(never $input): self;
    }
    
    class A implements CollectionInterface {
        public function add(int $input): self {}
    }
    

🛠 Tools

  • frontdevops/php-evil – An extension to disable eval(). It turns out that eval() is not a function, but a language construct, so disable_functions will not help to forbid it. So the author had to write his own micro-extension.
  • beyondcode/expose 2.0 – A cool tool for sneaking local services into the world. This should be useful for testing webhooks or demoing apps.
  • EcotoneFramework – An interesting service bus for DDD, CQRS, and Event Sourcing in PHP. It works in PHP 8+ via attributes, with good documentation and integrations for Laravel and Symfony. Here is an example of a CQRS implementation.
  • PHP-CSS-Parser – A Parser for CSS files written in PHP. This allows the extraction of CSS files into a data structure, manipulation of said structure, and output as (optimized) CSS.
  • Psalm 4.9.0 – The first community release of Psalm after Matt Brown, the author, left the project.
  • ergebnis/composer-normalize – A plugin for Composer that makes the composer.json file look nice.
  • paragonie/paseto 2.0 – Stateless-token, a safe alternative to JWT.
  • chrome-php/chrome v1.0.0 – A package to control Chrome/Chromium in headless mode.
  • darsyn/ip – Immutable value objects for working with IP addresses, including helpers for Doctrine
  • MadLisp – A Lisp interpreter written in PHP.

Symfony

Laravel

Yii

PhpStorm

  • i18n Ally – A nice plugin for PhpStorm for making easy work of translation strings. It’s automatically configured for Laravel and Symfony, and it can be manually configured for Yii, CodeIgniter, and CakePHP.
  • Laravel Idea 4.4 – A big update to the plugin.
  • 📺 Source diving the PhpStorm Pest plugin – Cool stream recording where Oliver Nybroe shows how to develop PhpStorm plugins.

💡 Misc

📺 Videos


Thanks for reading, we hope you have a great day!

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

Viewing all 104 articles
Browse latest View live