AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Code activate phpstorm3/7/2024 Version 8.1 is no exception, as it deprecates a lot of problematic legacy features. PHP has been known for its quirky behavior in some cases, but each new version cleans up many of these issues. In PhpStorm, convert fromCallable calls to the new syntax by pressing Alt+Enter and choosing a quick-fix from the dropdown list: The advantage is that the new syntax is accessible to static analysis, and it respects the scope at the point where the callable is created. Now you will be able to do the following instead: $fn = strlen(.) This is what it used to look like: $fn = Closure::fromCallable('strlen') This is called first-class callable syntax. In PHP 8.1 it is possible to get a reference to any function. PhpStorm validates all of the cases to help you use these new language features: However, you can’t use the new operator with properties or class constants because of problems with the initialization order. In PHP 8.1, objects can be used as default parameter values, static variables, and global constants, as well as in attribute arguments.Īs a cool side effect, this change makes nested attributes possible. PHP 8.1 allows you to declare final class constants so that they cannot be overridden in child classes. It’s great that this is a language feature now! This type improves code analysis and does pretty much the same thing that the # attribute has been doing in PhpStorm. PHP 8.1 features a new type for return values: never.Ī function or method declared with the never type indicates that it will not return a value and will either throw an exception or end the script’s execution by calling die(), exit(), trigger_error(), or something similar. Those are also supported in PhpStorm 2021.3, and when you decide to upgrade to PHP 8.1, you can add a native type declaration: In older PHP versions, it was quite common to use intersection types in PHPDoc annotations. This feature is called pure intersection types because combinations with union types are not supported and are being left for future consideration. In PhpStorm 2021.3, code completion for this is mostly the same as it is for union types, because a union can contain members of all involved types, and an intersection must contain members of all types. The syntax is TypeA&TypeB, and it means that the variable must be both instanceof TypeA and instanceof TypeB. Union types were added in PHP 8.0, and now PHP 8.1 is introducing intersection types. PhpStorm has an Alt+Enter quick-fix for this: That is, its internal state can still be changed.Ī readonly property cannot have a default value, but you can initialize it in the constructor as a promoted property. If a readonly property is initialized by an object, it does not become immutable. Properties with the readonly flag must be typed, but if you don’t know the specific type, then you can use the mixed type. This means you can assign a value either in the declaration itself or in a class method. It was possible to achieve similar behavior in previous versions of PHP with a private setter, but the readonly keyword makes classes cleaner and constraints stricter.Ī readonly property can only be initialized in the same scope where it’s declared. Readonly properties are properties that cannot be changed after initialization, meaning after a value is assigned to them. Learn more about enums support in PhpStorm. PhpStorm has supported PHP 8.1 Eums since the 2021.2 release. You can switch from the toolbar or by specifying the requirement in composer.json.Įnumerations can be used instead of a set of constants, and they provide type validation out of the box. Here’s what’s available and how you can use it in the IDE.Īs usual, you can try new features by setting the project language level to PHP 8.1. PhpStorm 2021.3 supports all of the latest language changes. PHP 8.1 has already been released! We would like to express our thanks to all the contributors and release managers! Read this blog post for details about all the significant updates, demonstrated through a ton of GIFs! Checkout and Rebase onto Current for remote branches.Output redirection to custom file or directory. Support for text streams and JSON streams.Quickly switch default server for project.Speedup for SFTP/FTP/FTPS with multithreaded connection.Drag and drop support for the Move Class refactoring.Support for the phpstan-* annotation for templates.Support for future Laravel 9 collections.Improved support for Doctrine Collections.This major release introduces full support for PHP 8.1, better handling of generics in PHP, remote development, improvements to deployment, an HTTP client, refactorings, and much more.
0 Comments
Read More
Leave a Reply. |