PHP Annotated – April 2020

栏目: IT技术 · 发布时间: 6年前

内容简介:Greetings everyone,This April edition of PHP Annotated reviews 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.

PHP Annotated – April 2020

Greetings everyone,

This April edition of PHP Annotated reviews 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.

:zap:️ News & Releases

  • PHP 7.4.5 , PHP 7.3.17 , and PHP 7.2.30 are released.
  • Composer v2.0 Alpha – April 5 marked exactly 9 years since the first commit to the Composer repository. You can now see what’s new and what has changed in the upcoming second major release. To try it right away, run: composer self-update --snapshot .
  • PhpStorm 2020.1 is out.

 PHP Internals

  • The PHP 8 release schedule is available. The first alpha is expected on June 18, and the final release is planned for December 3.
  • [RFC] Constructor Property Promotion – Larry Garfield has published a detailed analysis of PHP’s object ergonomics . Larry concludes that it would be best to focus on these three RFCs: constructor promotion, named parameters, and compound Property Visibility.
    And in the wake of the analysis, this RFC proposes allowing you to declare properties directly in the constructor. Instead of writing this:
     
    class Point {
        public float $x;
        public float $y;
        public float $z;
     
        public function __construct(
            float $x = 0.0,
            float $y = 0.0,
            float $z = 0.0
        ) {
            $this->x = $x;
            $this->y = $y;
            $this->z = $z;
        }
    }
     
    
    It will be possible to use the following:
     
    class Point {
        public function __construct(
            public float $x = 0.0,
            public float $y = 0.0,
            public float $z = 0.0
        ) {}
    }
     
    
  • [RFC] Allow trailing comma in parameter list – There is also a proposal to allow a comma to be used after the last parameter in a function definition. This has already worked since PHP 7.3 for the list of arguments in a function call.
     
    class Uri {
        private function __construct(
            ?string $scheme,
            ?string $user,
            ...
            ?string $query,
            ?string $fragment // <-- ARGH!
        ) {
            ...
        }
    }
     
    
  • [RFC] Stricter type checks for arithmetic/bitwise operators – This RFC offers to generate a TypeError when an arithmetic or bitwise operator is applied to an array, resource, or object.
     
    var_dump([] % [42]);
    // int(0)
    // WTF?
     
    
  • [RFC] Type casting in array destructuring expressions – See an example:
     
    [(int) $now, (int) $future] = ["2020", "2021"];
     
    // The same as the following
    [$now, $future] = ["2020", "2021"];
    $now = (int) $now;
    $future = (int) $future;
     
    
  • [RFC] throw expression – This proposal has been accepted, and in PHP 8 throw will no longer be a statement. Rather it will be an expression. This means it will be possible to throw an exception in arrow functions, ternary operators, and other constructions.
     
    $callable = fn() => throw new Exception();
     
    $foo = $bar['key'] ?? throw new KeyNotSetOnBarException();
     
    
  • [RFC] Attributes v2 – The proposal to bring attributes (annotations) into PHP core by Benjamin Eberlei and Martin Schröder has been greatly improved .
    It looks like the proposal has a good chance to pass . The syntax is also being voted on: <<>> vs. @: .
     
    <<ExampleAttribute>>
    class Foo
    {
        <<ExampleAttribute>>
        public $x;
     
        <<ExampleAttribute>>
        public function foo(<<ExampleAttribute>> $bar) { }
    }
     
    
  • [RFC] Mixed Type v2 – At the moment, if a function does not have its return type specified, it is not clear whether the developer forgot to specify it or deliberately chose not to specify it for some reason . Besides, the mixed pseudotype is already used in the PHP manual.
    Máté Kocsis and Danack suggest adding it in the PHP 8. The mixed type will be equivalent to a union of array|bool|callable|int|float|null|object|resource|string types.
  • [RFC] non-capturing catches – This is a proposal to make a variable declaration optional in the catch block:
     
    try {
        changeImportantData();
    } catch (PermissionException) { // The intention is clear: exception details are irrelevant
        echo "You don't have permission to do this";
    }
     
    
  • [RFC] Match expression – Instead of fixing the switch construct Ilija Tovilo proposes to introduce a match expression, that is devoid of all the switch flaws, such as the absence of type checks and the possibility to return a value. It can also be extended to pattern-matching in the future.
     
    $expressionResult = match ($condition) {
        1, 2 => foo(),
        3, 4 => bar(),
        default => baz(),
    };
     
    
  • [RFC] Pipe Operator v2 – This is the second attempt to introduce the |> operator for sequential function calls while passing the result of the previous function as an argument to the next one.
     
    $result = "Hello World"
        |> 'htmlentities'
        |> 'explode'
        |> fn($x) => array_map(fn($v) => 'strtoupper', $x)
        |> fn($x) => array_filter(fn($v) => $v != 'O');
     
    
  • Rejected: Server-Side Request and Response Objects , Userspace operator overloading , Write-Once (readonly) Properties , Compact Object Property Assignment .

 Tools

  • jlaswell/compote – A lightweight dependency management for PHP written in Go. It is not designed as a replacement for Composer but rather as a compliment for specific use-cases, CI for example. Currently, it can install locked dependencies and show locked dependencies for a project.
  • repman.io – A private PHP package repository manager for Composer.
    It also provides a proxy with CDN for packagist.org, which can speed up the download of packages.
  • dantleech/what-changed – A Composer plugin that generates change reports when you run composer update .
  • clue/graph-composer – This tool creates a graph of your project’s composer dependencies.
  • VKCOM/noverify v0.2.0 – A fast static analyzer written in Go for PHP. The release improves PHP 7 support, offers more diagnostics, and returns fewer false positives.
  • markrogoyski/math-php 1.0 – The first stable release of a math library for PHP.
  • ackintosh/ganesha 1.0 – A Circuit Breaker pattern implementation for PHP applications. Learn more in the blog post .
  • Spiral Framework – A high-performance hybrid PHP+Go framework.

Symfony

Laravel

Yii

Zend/Laminas

 Async PHP

  • hyperf/hyperf – A framework for building microservices or middlewares based on Swoole coroutines.
  • clue/reactphp-flux – This package allows you to limit the number of simultaneously executed competitive tasks in ReactPHP.

 Misc

 Videos

 Podcasts

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

Stay safe!

Your JetBrains PhpStorm team

The Drive to Develop


以上所述就是小编给大家介绍的《PHP Annotated – April 2020》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

不是为了快乐

不是为了快乐

宗萨蒋扬钦哲仁波切 / 姚仁喜 / 深圳报业集团出版社 / 2013-1 / 38.00元

前行修持是一套完整的实修系统,它既是一切佛法修持的根基,又囊括了所有修持的精华,以及心灵之道上所需的一切;既适合入门者打造学佛基本功,也是修行人需要终生修持的心法。书中除了实际的方法指导之外,还不断启发佛法的珍贵与修持的必要,并处处可见对学佛者的鼓舞和纠正,其最终的用心,是让我们踏上不间断的修持之路,真正转化我们僵硬、散乱和困惑的心。 在现代人看来,快乐,理应是最值得追求的目标。我们希望生活......一起来看看 《不是为了快乐》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具