PHP Annotated – April 2020

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

内容简介: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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

YC创业营: 硅谷顶级创业孵化器如何改变世界

YC创业营: 硅谷顶级创业孵化器如何改变世界

兰德尔·斯特罗斯 (Randall Stross) / 苏健 / 浙江人民出版社 / 2014-8-1 / CNY 52.90

在互联网创业成本日益降低、融资却越来越难的今天,硅谷的Y Combinator因何成为全世界创业者趋之若鹜的创业圣地?为什么25岁左右的青年最适合创业?创业者如何才能在遴选面试中脱颖而出?为什么YC特别看好那些主要由黑客组成的创业团队? YC真的歧视女性吗?如何想出能够赢得投资的新点子?创业者应该如何寻找联合创始人? 获准进入Y Combinator及其创业公司全程跟踪批量投资项目的第一人,......一起来看看 《YC创业营: 硅谷顶级创业孵化器如何改变世界》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具