Road to PHP 8
Welcome to this repository which showcases some of the interesting features of PHP 8.
Topics
- Union types
- Named arguments
- Exception improvements
- Match expression
mixed
type- Constructor property promotion
- Nullsafe operator
- Weak maps
- Attributes
- Object classnames
- Stringable interface
- New string functions
- Trailing comma in function calls
Slides
Slides can be downloaded here.
PHP 8 environment
You can either install PHP 8 locally to run the code examples or use the provided helper script to run the examples inside Docker container.
Installing PHP 8
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.0-cli
In case if you need to install some of the php extensions:
sudo apt install php8.0-[extname]
Installation of PHP 8 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
Running example in Docker container
Use the run
helper script to run the code example inside Docker container:
./run 1_union_types/index.php