Categories
BEST PHP CODE

New Features php-7.4

source : https://raw.githubusercontent.com/php/php-src/php-7.4.0beta4/UPGRADING

========================================
2. New Features
========================================

- Core:
  . Added support for typed properties. For example:

        class User {
            public int $id;
            public string $name;
        }

    This will enforce that $user->id can only be assigned integers and
    $user->name can only be assigned strings. For more information see the
    RFC: https://wiki.php.net/rfc/typed_properties_v2



  . Added support for coalesce assign (??=) operator. For example:

        $array['key'] ??= computeDefault();
        // is roughly equivalent to
        if (!isset($array['key'])) {
            $array['key'] = computeDefault();
        }

    RFC: https://wiki.php.net/rfc/null_coalesce_equal_operator

  . Added support for unpacking inside arrays. For example:

        $arr1 = [3, 4];
        $arr2 = [1, 2, ...$arr1, 5];
        // $arr2 == [1, 2, 3, 4, 5]

    RFC: https://wiki.php.net/rfc/spread_operator_for_array

.php.net/rfc/tostring_exceptions

Leave a Reply