Welcome to this repository which showcases some of the interesting features of PHP 8.1.
- Enumerations
- Readonly properties
- Intersection types
- Fibers
never
return typefinal
class constants- First-class callable
- Array unpacking with string keys
new
keyword in initializer- Other changes
Slides can be downloaded here.
You can either install PHP 8.1 locally to run the code examples or use the provided helper script to run the examples inside Docker container.
Add the ondrej/php
repository to you Ubuntu machine:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
Install only cli package, it should be enough:
sudo apt install php8.1-cli
In case if you need to install some of the php extensions:
sudo apt install php8.1-[extname]
Installation of PHP 8.1 will set is as default PHP environment on your machine. To set the PHP 7.4 as the default environment, run the following commands:
sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
sudo update-alternatives --set phpize /usr/bin/phpize7.4
sudo update-alternatives --set php-config /usr/bin/php-config7.4
Use the run
helper script to run the code example inside Docker container:
./run.sh 01_enums/01_class_with_constants.php
Don't forget to add proper permissions to run.sh
script:
chmod +x run.sh
NOTE: This repository was inspired by: