PHP Digest # 194 (1. - 14. Dezember 2020)



Neue Auswahl mit Links zu Nachrichten und Materialien. In der Version: Enum in PHP 8.1, Serializable Removal und $ GLOBALS Limitation sowie weitere Neuigkeiten von PHP Internals, PhpStorm 2020.3, Symfony UX, ein Teil nĂŒtzlicher Tools, ein Video und der erste PHP Digest Stream.



Viel Spaß beim Lesen!









Nachrichten und Veröffentlichungen



  • habr PhpStorm 2020.3 : PHP 8, Attribute, PHPStan und Psalm, Xdebug 3, RĂŒckenwind CSS und Co-Entwicklung.
  • 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









/





Unterhaltsam











Heute werde ich zum ersten Mal den PHP-Digest streamen. Alle Neuigkeiten und Links aus der Ausgabe + weitere Details, eine Übersicht ĂŒber das, was gesendet wurde, interessant, aber nicht in der Ausgabe enthalten, und ein Wettbewerb mit Elefanten.

Ab 20:00 Uhr Moskau, Minsk / 19:00 Uhr Kiew.






Wenn Sie einen Fehler oder eine Ungenauigkeit bemerken, teilen Sie uns dies bitte in einem persönlichen Habr oder Telegramm mit .





Weitere Neuigkeiten und Kommentare zum PHP Digest Telegram-Kanal .



Link senden

Links in allen Digests suchen

← Vorherige Ausgabe: PHP-Digest # 193




All Articles