PHP-Digest # 194 (December 1 - 14, 2020)



Fresh selection with links to news and materials. In the release: Enum in PHP 8.1, Serializable removal and $ GLOBALS limitation, plus other news from PHP Internals, PhpStorm 2020.3, Symfony UX, a portion of useful tools, a video, and the first PHP Digest Stream.



Enjoy reading!









News and releases



  • habr PhpStorm 2020.3 : PHP 8, Attributes, PHPStan and Psalm, Xdebug 3, Tailwind CSS and Co-development.
  • JetBrains Qodana EAP β€” JetBrains PhpStorm CI.
  • Slack $27 β€” , PHP, Hack.
  • WordPress 5.6 β€” C - PHP 8.
  • PHP – 2020.2 β€” , Composer packagist.org.

    β€’ PHP 7.4: 42.61% (+22.55)

    β€’ PHP 7.3: 27.05% (-3.00)

    β€’ PHP 7.2: 15.28% (-12.21)

    β€’ PHP 7.1: 7.45% (-4.1)

    β€’ PHP 5.6: 2.71% (-2.28)

    β€’ PHP 7.0: 2.70% (-1.30)



PHP Internals



  • [RFC] Deprecate passing null to non-nullable arguments of internal functions β€” PHP null



    , nullable



    . , str_contains("", null)







    , , null .



    str_contains("", null);
    // > No errors
    
    function _str_contains ( string $haystack , string $needle ) : bool
    {
        return true;
    }
    
    _str_contains("", null);
    // > Fatal error: Uncaught TypeError: Argument 2 passed to _str_contains() must be of the type string, null given
    
          
          





    8.1 deprecation notice.



    declare(strict_types=1);



    .
  • [RFC] Restrict $GLOBALS usage β€” , $GLOBALS



    , INDIRECT



    PHP. PHP.



    RFC $GLOBALS



    .



    , , isset unset:



    $GLOBALS['x'] = 1;
    
    echo $GLOBALS['x']
    
    isset($GLOBALS['x']);
    unset($GLOBALS['x']);
          
          





    .



    $GLOBALS :



    $GLOBALS = [];
    $GLOBALS =& $x;
    $x =& $GLOBALS;
    unset($GLOBALS);
          
          





    , $GLOBALS



    :



    asort($GLOBALS);
    // > Compile-time error
          
          





    : : Β« PHPΒ».
  • [RFC] Phasing out Serializable β€” 7.4 : Serialiazable



    __serialize()



    __unserialize()



    .



    Serializable



    . PHP 8.1 deprecation notice, PHP 9.0 β€” compile-time error.
  • [RFC] Enumerations β€” Ilija Tovilo Larry Garfield enum RFC, Swift, Rust, Kotlin.



    Enum , β€” . , , Β« Enums XΒ» Β« , Β». .



    enum



    case



    :



    enum Suit {
      case Hearts;
      case Diamonds;
      case Clubs;
      case Spades;
    }
          
          





    :



    $val = Suit::Diamonds;
    
    function pick_a_card(Suit $suit) { ... }
    
    pick_a_card($val);        // OK
    pick_a_card(Suit::Clubs); // OK
    pick_a_card('Spades');    // TypeError
          
          





    Enum -:



    $a = Suit::Spades;
    $b = Suit::Spades;
    
    $a === $b; // true
    
    $a instanceof Suit;         // true
    $a instanceof Suit::Spades; // true
          
          





    Enum. , :



    enum Suit: string {
      case Hearts = 'H';
      case Diamonds = 'D';
      case Clubs = 'C';
      case Spades = 'S';
    }
    
    echo "I hope I draw a " . Suit::Spades;
    // prints "I hope I draw a S".
          
          





    Enum , . :



    enum UserStatus: string {
      case Pending = 'pending';
      case Active = 'active';
      case Suspended = 'suspended';
      case CanceledByUser = 'canceled';
    
      public function label(): string {
        return match($this) {
          UserStatus::Pending => 'Pending',
          UserStatus::Active => 'Active',
          UserStatus::Suspended => 'Suspended',
          UserStatus::CanceledByUser => 'Canceled by user',
        };
      }
    }
    
    foreach (UserStatus::cases() as $key => $val) {
      printf('<option value="%s">%s</option>\n', $key, $val->label());
    }
          
          





    :



    • case?
    • ? function stuff(Suit::Heart|Suit:Diamond $card) { ... }



    • Enum?
    • < enum



      ? , Enum



      . : enum class UserStatus {...}





  • [RFC] Algebraic Data Types β€” Enum PHP. ** tagged unions pattern matching.
  • [RFC] Direct execution opcode file without php source code file β€” . , - .pyc / .pyo



    .



    PHP . , <?phpo%php_version_id%



    .



    include()



    , include_once()



    , require()



    , require_once()



    .
  • [RFC] Wall-Clock Time Based Execution Timeout β€” PHP . sleep() . , ini- max_execution_time



    .



    RFC max_execution_wall_time



    , .






Symfony





Laravel





Yii





Async PHP









/





Entertaining











Today I will stream the PHP digest for the first time. All news and links from the issue + more details, an overview of what was sent, interesting but not included in the issue, and a contest with elephants.

Beginning at 20:00 Moscow, Minsk / 19:00 Kiev.






If you notice an error or inaccuracy - please let us know in a personal habr or telegram .





More news and comments on the PHP Digest Telegram channel .



Send link

Search links in all digests

← Previous issue: PHP-Digest β„– 193




All Articles