├── .gitignore ├── README.md ├── composer.json ├── composer.lock ├── index.php └── src ├── 01_enums.php ├── 02_array_unpacking.php ├── 03_readonly_properties.php ├── 04_intersection_types.php ├── 05_first_class_callable_syntax.php ├── 06_array_is_list_function.php ├── 07_final_class_constants.php ├── 08_new_in_initializers.php ├── 09_named_arguments_after_unpacking.php └── 10_explicit_octal_integer_literal_notation.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | vendor 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What's new in PHP8.1 2 | 3 | The repository is made for YouTube Video [What's new in PHP 8.1](https://youtu.be/RaVfeBfUlkk) 4 | 5 | ## In this repository I cover changes made in PHP 8.1 6 | 7 | 8 | - Enums 9 | - Array unpacking with string values 10 | - Readonly properties 11 | - Intersection types 12 | - First class callable syntax 13 | - array_is_list function 14 | - Final class constants 15 | - new in initializers 16 | - Names arguments after unpacking 17 | - Octal literal notation 18 | - Migrating from php8.0 to php8.1 19 | - Fibers 20 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thecodeholic/php8.1", 3 | "authors": [ 4 | { 5 | "name": "Zura Sekhniashvili", 6 | "email": "sekhniashvilizura@gmail.com" 7 | } 8 | ], 9 | "autoload": { 10 | "psr-4": { 11 | "app\\": "./src" 12 | } 13 | }, 14 | "require": { 15 | "php": "^8.1" 16 | } 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "465368b3190abc61c95e53d31a235fb3", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "stable", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": { 16 | "php": "^8.1" 17 | }, 18 | "platform-dev": [], 19 | "plugin-api-version": "2.0.0" 20 | } 21 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 'User is active', 20 | self::Pending => 'User is pending', 21 | self::Deleted => 'User is deleted', 22 | }; 23 | } 24 | 25 | public static function staticMethod() 26 | { 27 | return "Hello from static"; 28 | } 29 | 30 | public static function hello() 31 | { 32 | return "hello from interface"; 33 | } 34 | } 35 | 36 | echo '
';
37 | var_dump(UserStatus::Pending->hello());
38 | echo '
'; 39 | 40 | echo '
';
41 | var_dump(UserStatus::hello());
42 | echo '
'; 43 | 44 | echo '
';
45 | var_dump(UserStatus::cases());
46 | echo '
';; 47 | 48 | -------------------------------------------------------------------------------- /src/02_array_unpacking.php: -------------------------------------------------------------------------------- 1 | 'John', 8 | 'surname' => 'Doe' 9 | ]; 10 | 11 | $user = [ 12 | ...$defaultUser, 13 | ...['age' => 30], 14 | 'name' => 'Zura' 15 | ]; 16 | 17 | echo '
';
18 | var_dump($user);
19 | echo '
'; 20 | -------------------------------------------------------------------------------- /src/03_readonly_properties.php: -------------------------------------------------------------------------------- 1 | user = $user; 13 | } 14 | } 15 | 16 | $order = new Order('John', 100); 17 | echo '
';
18 | var_dump($order);
19 | echo '
'; 20 | 21 | $order->user = 'Zura'; 22 | 23 | echo '
';
24 | var_dump($order);
25 | echo '
'; 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/04_intersection_types.php: -------------------------------------------------------------------------------- 1 | '; 8 | var_dump($closure('hello world')); 9 | echo '';; 10 | -------------------------------------------------------------------------------- /src/06_array_is_list_function.php: -------------------------------------------------------------------------------- 1 | '; 6 | var_dump(array_is_list($numbers)); // true 7 | echo ''; 8 | 9 | $mixed = [1, 2, 3, 4, 'name' => 'John']; 10 | echo '
';
11 | var_dump(array_is_list($mixed)); // false
12 | echo '
'; 13 | -------------------------------------------------------------------------------- /src/07_final_class_constants.php: -------------------------------------------------------------------------------- 1 | '; 14 | var_dump(SubClass::PI); 15 | echo ''; 16 | -------------------------------------------------------------------------------- /src/08_new_in_initializers.php: -------------------------------------------------------------------------------- 1 | '; 17 | var_dump($user); 18 | echo ''; 19 | -------------------------------------------------------------------------------- /src/09_named_arguments_after_unpacking.php: -------------------------------------------------------------------------------- 1 | '; 7 | var_dump(0o11 === 9); 8 | echo ''; 9 | 10 | --------------------------------------------------------------------------------