Result of our code-along meetup writing PHP 8.1 code

Overview

PHP 8.1 Demo Code

This code demonstrates various PHP 8.0 and 8.1 features in a realistic, functional (but incomplete) codebase. The code is part of some DNS validation logic.

This code came from a code along session in the October 2021 Arizona PHP User Group meetup, and was inspired by some refactoring work I was doing at my day job.

Feature Sightings

  • Enums
  • Throw exceptions as an expression
  • Constructor property promotion
  • Readonly properties
  • Union types
  • static return type
  • First class callables
  • new in initializers
  • match expressions
  • Trailing commas in parameter lists
  • catch exceptions without a variable

Running the Code

Requirements

  • Docker
  • PHP
  • Composer

Instructions

  1. Uncomment lines 10 and 11 in index.php.
    • This is because you are running Composer locally, and not in the container, so the current version of Composer you have will not include the enums in with the autoloader.
  2. Run composer run shell to download the php 8.1 image and boot up a docker container for it with a shell.
  3. Run php index.php within the container's shell to execute this file.
  4. Run exit to exit and shutdown the container.

Resources

You might also like...
A pure PHP library for reading and writing presentations documents
A pure PHP library for reading and writing presentations documents

Branch Master : Branch Develop : PHPPresentation is a library written in pure PHP that provides a set of classes to write to different presentation fi

Music website developed as a final group project for our Webpage Development class.

double-drummer Music listening website developed as final group project for our Webpage Development course. All parts that disclosed any information r

Show caffeine intake stats for our office coffee machine
Show caffeine intake stats for our office coffee machine

Coffee brewing statistics for the Spatie office Over at Spatie we drink a lot of coffee. How much coffee? We had no idea until we created this dashboa

RedeemeRadio is the radio station of Alexander Schliker, our Redeemer and Super Hero (he actually flies).

RedeemeRadio - README Welcome to the RedeemeRadio project -- an open source project for allowing broadcasting the radio of Alexander Schliker, our Sup

Learn how to run WordPress with Docker. Read about our experiences and start off with an easy boilerplate.
Learn how to run WordPress with Docker. Read about our experiences and start off with an easy boilerplate.

Hi! We're Dan and Jay. We're a two person team with a passion for open source products. We created Server Side Up to help share what we learn. Find us

Rocket Web Prime theme based on Magento Blank that includes our most common customizations.
Rocket Web Prime theme based on Magento Blank that includes our most common customizations.

RW Prime - Magento 2 boilerplate theme RW Prime theme is based on Magento Blank and includes our most common customizations that we make on the majori

 A complete solution for group projects in organizations that lets you track your work in any scenario. Working in a team is a cumbersome task, ease it using our project management system.
A complete solution for group projects in organizations that lets you track your work in any scenario. Working in a team is a cumbersome task, ease it using our project management system.

SE-Project-Group24 What is Evolo? Evolo is Dashboard based Project Management System. A complete solution for group projects in organizations that let

Dead Code Detector (DCD) for PHP code.

This project is no longer maintained and its repository is only kept for archival purposes. PHP Dead Code Detector (PHPDCD) phpdcd is a Dead Code Dete

⚗️ Adds code analysis to Laravel improving developer productivity and code quality.
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

Owner
azPHP
Phoenix area PHP Developer Group
azPHP
Hi everyone! This is our repository for our final project in college. We're sorry if so many bug or error. Thank You

About The Project Hi everyone! This is our repository for our final project in college. We're sorry if so many bug or error. Thank You About Laravel L

Lintang Bima Sakti 3 Dec 9, 2021
Buy and sell crypto top 100 crypto with our fake currency. Donate to and use our referal links for discounts

PLEASE ENABLE SQLITE3 AND GD OR GD2 IN XAMPP TO RUN THE APP! (SEE HOW_TO_SETUP_XAMPP.gif) ![alt text](https://github.com/Tby23rd/Project1-Cryptosimul

Tabitha Maru 0 Dec 26, 2021
This is an experiment to export all RFCs from the PHP wiki into Git, including the change history for each RFC (along with the date and author of each change). This is not meant to replace the wiki.

PHP Requests for Comments (RFCs) About This repository is an experiment to export all RFCs from the PHP wiki into Git, including the change history fo

Ben Ramsey 34 Jun 20, 2022
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

null 2 Nov 20, 2021
The package provides the ability to write logs into the database synchronously or asynchronously, along with other logging channels.

Laravel database log channel The package provides the ability to write logs into the database synchronously or asynchronously, along with other loggin

Jarosław Goszowski 18 Nov 28, 2022
Reference for writing clear PHP code

clearPHP Reference for writing clear PHP code It is difficult to know when one's code is well written. There are recommendations for writing PHP code

Seguy Damien 947 Dec 22, 2022
Test essentials for writing testable code that interacts with Magento core modules

Essentials for testing Magento 2 modules Using mocking frameworks for testing Magento 2 modules is counterproductive as you replicate line by line you

EcomDev B.V. 9 Oct 6, 2022
PHP OOP interface for writing Slack Block Kit messages and modals

Slack Block Kit for PHP ?? For formatting messages and modals for Slack using their Block Kit syntax via an OOP interface ?? By Jeremy Lindblom (@jere

Slack PHP Framework 32 Dec 20, 2022
A library for reading and writing DNA test kit files in PHP.

php-dna Requirements php-dna 1.0+ requires PHP 8.0 (or later). Installation There are two ways of installing php-dna. Composer To install php-dna in y

Family Tree 365 4 Aug 31, 2022
PHP implementation for reading and writing Apache Parquet files/streams

php-parquet This is the first parquet file format reader/writer implementation in PHP, based on the Thrift sources provided by the Apache Foundation.

null 17 Oct 25, 2022