The document discusses PHP 8.1 enums, including why enums are needed, how they can help, how enums work in PHP 8.1, and examples of using enums. Key points include: enums allow for stronger typing than constants, make invalid values impossible, and improve code readability and maintainability. Enums in PHP 8.1 can have zero or more members, members are objects, and enums can be namespaced and autoloaded.
PHP 8.1 brings Enums, one of the most requested features in PHP.
Enums, or Enumerations, allow creating strict and type-safe structures for fixed values. An Enum structure can hold a number of values that can also be backed with integer or string values.
In this comprehensive session, we will discover what Enums are, why they are useful, how to apply them on our applications including Drupal, and things to watch out for when using Enums.
Audience
This session is for those who are familiar with modern PHP practices such as Object Oriented Programming, and principles such as Liskov Substitution principle. A quick introduction will be given to catch up to speed, but familiarity with such concepts can help a lot.
What you will learn
What are Enums.
Why Enums are useful.
How to use Enums
Migrating from magic constants/values to Enums.
Backed Enums and storing/fetching Enum values with a database.
Using Enums in a Drupal context.
Caveats when using Enums.
Author
Ayesh Karunaratne is the author of PHP.Watch (https://php.watch), where he provides in-depth articles and documents on PHP and latest changes to the language.
PHP 8.0: https://php.watch/versions/8.0
PHP 8.1: https://php.watch/versions/8.1
Enums: https://php.watch/versions/8.1/enums
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
Cette conférence présente deux grands motifs de conception : l'observateur et l'injection de dépendance. Ce sujet allie à la fois théorie et pratique. Le composant autonome EventDispatcher de Symfony ainsi que le conteneur d'injection de dépendance Pimple sont mis à l'honneur avec des exemples pratiques d'usage. Ces cas pratiques combinent du code de l'ORM Propel ainsi que le composant autonome Zend\Search\Lucene du Zend Framework 2
With Extbase - a new framework for extension development introduced in TYPO3 4.3 - you are able to develop with the paradigms of FLOW3 today. During this talk, you get in touch with the features of the framework to understand how it supports your development process to develop clean code cost efficient in less time. Extbase is one cornerstone for a smooth transition to TYPO3 v5, another is reusable business domain knowledge in form of Generic Domain Models available in 4.x and 5.x. The Generic Domain Models will enable you to add a Semantic Web topping.
This talk is an overview of the history of the PHP language and major framework projects that have emerged in the last 5 years. It examines what we've learned in the development of these frameworks, how that education has been brought to bear in Lithium. Most of this talk ended up being me demoing and answering questions, so there's not a lot of content in the slides, sorry.
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
Have you ever used PHP's built in reflection, only to find you can't do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren't loaded, so that you can modify them directly?
Better Reflection is an awesome new library that uses magical time-warp techniques* (*actual magic or time-warp not guaranteed) to improve on PHP's built-in reflection by providing additional functionality. In this talk we'll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.
PHP 8.1 brings Enums, one of the most requested features in PHP.
Enums, or Enumerations, allow creating strict and type-safe structures for fixed values. An Enum structure can hold a number of values that can also be backed with integer or string values.
In this comprehensive session, we will discover what Enums are, why they are useful, how to apply them on our applications including Drupal, and things to watch out for when using Enums.
Audience
This session is for those who are familiar with modern PHP practices such as Object Oriented Programming, and principles such as Liskov Substitution principle. A quick introduction will be given to catch up to speed, but familiarity with such concepts can help a lot.
What you will learn
What are Enums.
Why Enums are useful.
How to use Enums
Migrating from magic constants/values to Enums.
Backed Enums and storing/fetching Enum values with a database.
Using Enums in a Drupal context.
Caveats when using Enums.
Author
Ayesh Karunaratne is the author of PHP.Watch (https://php.watch), where he provides in-depth articles and documents on PHP and latest changes to the language.
PHP 8.0: https://php.watch/versions/8.0
PHP 8.1: https://php.watch/versions/8.1
Enums: https://php.watch/versions/8.1/enums
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
Cette conférence présente deux grands motifs de conception : l'observateur et l'injection de dépendance. Ce sujet allie à la fois théorie et pratique. Le composant autonome EventDispatcher de Symfony ainsi que le conteneur d'injection de dépendance Pimple sont mis à l'honneur avec des exemples pratiques d'usage. Ces cas pratiques combinent du code de l'ORM Propel ainsi que le composant autonome Zend\Search\Lucene du Zend Framework 2
With Extbase - a new framework for extension development introduced in TYPO3 4.3 - you are able to develop with the paradigms of FLOW3 today. During this talk, you get in touch with the features of the framework to understand how it supports your development process to develop clean code cost efficient in less time. Extbase is one cornerstone for a smooth transition to TYPO3 v5, another is reusable business domain knowledge in form of Generic Domain Models available in 4.x and 5.x. The Generic Domain Models will enable you to add a Semantic Web topping.
This talk is an overview of the history of the PHP language and major framework projects that have emerged in the last 5 years. It examines what we've learned in the development of these frameworks, how that education has been brought to bear in Lithium. Most of this talk ended up being me demoing and answering questions, so there's not a lot of content in the slides, sorry.
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
Have you ever used PHP's built in reflection, only to find you can't do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren't loaded, so that you can modify them directly?
Better Reflection is an awesome new library that uses magical time-warp techniques* (*actual magic or time-warp not guaranteed) to improve on PHP's built-in reflection by providing additional functionality. In this talk we'll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.
Persistence is one of the most important part in a PHP project. Persisting data to a database came with PHP/FI and its MySQL support. From native extensions and PHP4 database abstraction libraries to PDO and modern ORM frameworks, you will (re)discover how persistence has evolved during the last decade. This talk will also introduce the future of data persistence with the growing success of alternative storage engines.
This session introduces most well known design patterns to build PHP classes and objects that need to store and fetch data from a relational databases. The session will describe the difference between of the Active Record, the Table and Row Data Gateway and the Data Mapper pattern. We will also examine some technical advantages and drawbacks of these implementations. This talk will expose some of the best PHP tools, which ease database interactions and are built on top of these patterns.
Lithium: The Framework for People Who Hate FrameworksNate Abele
This is the presentation was given at ConFoo on March 11th by Nate Abele and Joël Perras, and is an introduction to the architectural problems with other frameworks that Lithium was designed to address, and how it addresses them. It also introduces programming paradigms like functional and aspect-oriented programming which address issues that OOP doesn't account for.
Finally, the talk provides a quick overview of the innovative and unparalleled features that Lithium provides, including the data layer, which supports both relational and non-relational databases.
Silex is a brand new PHP 5.3 micro framework built on top of the Symfony2 de decoupled components. In this session, we will discover how to build and deploy powerful REST web services with such a micro framework and its embedded tools.
The first part of this talk will introduce the basics of the REST architecture. We fill focus on the main concepts of REST like HTTP methods, URIs and open formats like XML and JSON.
Then, we will discover how to deploy REST services using most of interesting Silex tools like database abstraction layer, template engine and input validation. We will also look at unit and functional testing frameworks with PHPUnit and HTTP caching with Edge Side Includes and Varnish support to improve performances.
Building Lithium Apps (Like a Boss) was a workshop presented on the structure and philosophy of the Lithium framework and its applications, and how best to take advantage of them.
Go beyond the documentation and explore some of what's possible if you stretch symfony to its limits. We will look at a number of aspects of symfony 1.4 and Doctrine 1.2 and tease out some powerful functionality you may not have expected to find, but will doubtless be able to use. Topics covered will include routing, forms, the config cache and record listeners. If you're comfortable in symfony and wondering what's next, this session is for you.
Symfony components in the wild, PHPNW12Jakub Zalas
Symfony is a set of reusable and decoupled PHP components designed to solve common web development problems. While as a framework it might not be the best for some of your projects, you can always build on top of its solid foundation of well written, tested and flexible components.
Original presentation: https://docs.google.com/presentation/pub?id=136blt1DWJ95yuEdpmjz9dIqgg38VwEXBQlY7bu0Op8w&start=false&loop=false&delayms=3000
Un gioco in cui vincono tutti o due piccioni con una fava ;)
Lavorare rivolti alla creazione di valore per il cliente e da questo ottenere una libreria quasi pronta per essere pubblicata
UK Symfony Meetup, November 2012
Original presentation: https://docs.google.com/presentation/pub?id=1PLcqTby6yqSbfWlMIDHknH852DU6DO6OAgQJOtSEdsg&start=false&loop=false&delayms=3000
PHP 8.1 brings Enums, one of the most requested features in PHP.
Enums, or Enumerations, allow creating strict and type-safe structures for fixed values. An Enum structure can hold a number of values that can also be backed with integer or string values.
In this comprehensive session, we will discover what Enums are, why they are useful, how to apply them on our applications, and things to watch out for when using Enums.
The REST API is an awesome plugin to expose your data from the WordPress core. But … the standard implementation might not fit your specific case.
Just like the WordPress core, you'll be able to extend it to your specific needs. I'll show you how to handle authentication, introduce caching strategies, alter custom post types, or even change the default way of communication altogether.
Persistence is one of the most important part in a PHP project. Persisting data to a database came with PHP/FI and its MySQL support. From native extensions and PHP4 database abstraction libraries to PDO and modern ORM frameworks, you will (re)discover how persistence has evolved during the last decade. This talk will also introduce the future of data persistence with the growing success of alternative storage engines.
This session introduces most well known design patterns to build PHP classes and objects that need to store and fetch data from a relational databases. The session will describe the difference between of the Active Record, the Table and Row Data Gateway and the Data Mapper pattern. We will also examine some technical advantages and drawbacks of these implementations. This talk will expose some of the best PHP tools, which ease database interactions and are built on top of these patterns.
Lithium: The Framework for People Who Hate FrameworksNate Abele
This is the presentation was given at ConFoo on March 11th by Nate Abele and Joël Perras, and is an introduction to the architectural problems with other frameworks that Lithium was designed to address, and how it addresses them. It also introduces programming paradigms like functional and aspect-oriented programming which address issues that OOP doesn't account for.
Finally, the talk provides a quick overview of the innovative and unparalleled features that Lithium provides, including the data layer, which supports both relational and non-relational databases.
Silex is a brand new PHP 5.3 micro framework built on top of the Symfony2 de decoupled components. In this session, we will discover how to build and deploy powerful REST web services with such a micro framework and its embedded tools.
The first part of this talk will introduce the basics of the REST architecture. We fill focus on the main concepts of REST like HTTP methods, URIs and open formats like XML and JSON.
Then, we will discover how to deploy REST services using most of interesting Silex tools like database abstraction layer, template engine and input validation. We will also look at unit and functional testing frameworks with PHPUnit and HTTP caching with Edge Side Includes and Varnish support to improve performances.
Building Lithium Apps (Like a Boss) was a workshop presented on the structure and philosophy of the Lithium framework and its applications, and how best to take advantage of them.
Go beyond the documentation and explore some of what's possible if you stretch symfony to its limits. We will look at a number of aspects of symfony 1.4 and Doctrine 1.2 and tease out some powerful functionality you may not have expected to find, but will doubtless be able to use. Topics covered will include routing, forms, the config cache and record listeners. If you're comfortable in symfony and wondering what's next, this session is for you.
Symfony components in the wild, PHPNW12Jakub Zalas
Symfony is a set of reusable and decoupled PHP components designed to solve common web development problems. While as a framework it might not be the best for some of your projects, you can always build on top of its solid foundation of well written, tested and flexible components.
Original presentation: https://docs.google.com/presentation/pub?id=136blt1DWJ95yuEdpmjz9dIqgg38VwEXBQlY7bu0Op8w&start=false&loop=false&delayms=3000
Un gioco in cui vincono tutti o due piccioni con una fava ;)
Lavorare rivolti alla creazione di valore per il cliente e da questo ottenere una libreria quasi pronta per essere pubblicata
UK Symfony Meetup, November 2012
Original presentation: https://docs.google.com/presentation/pub?id=1PLcqTby6yqSbfWlMIDHknH852DU6DO6OAgQJOtSEdsg&start=false&loop=false&delayms=3000
PHP 8.1 brings Enums, one of the most requested features in PHP.
Enums, or Enumerations, allow creating strict and type-safe structures for fixed values. An Enum structure can hold a number of values that can also be backed with integer or string values.
In this comprehensive session, we will discover what Enums are, why they are useful, how to apply them on our applications, and things to watch out for when using Enums.
The REST API is an awesome plugin to expose your data from the WordPress core. But … the standard implementation might not fit your specific case.
Just like the WordPress core, you'll be able to extend it to your specific needs. I'll show you how to handle authentication, introduce caching strategies, alter custom post types, or even change the default way of communication altogether.
This is a "PHP 201" presentation that was given at the December 2010 Burlington, Vermont PHP Users group meeting. Going beyond the basics, this presentation covered working with arrays, functions, and objects.
Come to this talk prepared to learn about the Doctrine PHP open source project. The Doctrine project has been around for over a decade and has evolved from database abstraction software that dates back to the PEAR days. The packages provided by the Doctrine project have been downloaded almost 500 million times from packagist. In this talk we will take you through how to get started with Doctrine and how to take advantage of some of the more advanced features.
Type hints were introduced with PHP 5. PHP 7 will add the ability to type hint on scalars and even to explicitly state what type will be returned from the function. This talk briefly goes over these added features to PHP 7.
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...Mateusz Zalewski
Czysty kod. Jakościowe oprogramowanie. Dobre praktyki. Święte Graale pracy programisty, o których każdy z nas wie, a mimo to wciąż zachowujemy się tak, jakby ich nie było. Bo przecież ten kod to tylko na chwilę. A tego to w ogóle nie będziemy używać. A tę klasę się zrefaktoruje później. Wszyscy od czasu do czasu zaciągamy dług u samych z siebie z przyszłości - dług, którego potem (nie bez powodu) bardzo nie chcemy spłacać.
Zagłębmy się więc w ten fascynujący świat słabego oprogramowania. Przejdźmy przez las nieużytych wzorców projektowych, przebrnijmy przez bagna zagnieżdżonych pętli. Wejdźmy na kolejny ośmiotysięcznik, a może z jego szczytu uda nam się dojrzeć zatokę pięknego kodu - w której, miejmy nadzieję, tym razem pozostaniemy na dłużej.
The REST API is an awesome plugin to expose your data from the WordPress core. But … the standard implementation might not fit your specific case.
Just like the WordPress core, you'll be able to extend it to your specific needs. I'll show you how to handle authentication, introduce caching strategies, alter custom post types, or even change the default way of communication altogether.
Early in year 2000 Robert C. Martin, aka "Uncle Bob", introduced his thoughts in an article about some of five basic principles on object oriented programming to the open world. What he probably did not expect was, that this 5 principles became the standard for object oriented programming.
This Talk is about those principles: Single responsibility, Open/close, Liskov substitution, Interface segregation, and Dependency inversion, or shorter S.O.L.I.D. principles. It will give you an introduction about these principles, their meaning, and where they should be recognized and applied. Examples from my daily work will show you the practical aspects of those principles.
Internationalizing CakePHP ApplicationsPierre MARTIN
Slides from the talk given by Mariano Iglesias during the CakeFest #3 - July 2009
Note: the original pdf and the code related to this talk can be found on cakephp.org (http://cakephp.org/downloads/CakeFest/CakeFest%203%20-%20Berlin%202009/Mariano%20Iglesias%20-%20Internationalizing%20CakePHP%20Applications)
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Łukasz Chruściel
No one wants their application to drag like a car stuck in the slow lane! Yet it’s all too common to encounter bumpy, pothole-filled solutions that slow the speed of any application. Symfony apps are not an exception.
In this talk, I will take you for a spin around the performance racetrack. We’ll explore common pitfalls - those hidden potholes on your application that can cause unexpected slowdowns. Learn how to spot these performance bumps early, and more importantly, how to navigate around them to keep your application running at top speed.
We will focus in particular on tuning your engine at the application level, making the right adjustments to ensure that your system responds like a well-oiled, high-performance race car.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
In the ever-evolving landscape of technology, enterprise software development is undergoing a significant transformation. Traditional coding methods are being challenged by innovative no-code solutions, which promise to streamline and democratize the software development process.
This shift is particularly impactful for enterprises, which require robust, scalable, and efficient software to manage their operations. In this article, we will explore the various facets of enterprise software development with no-code solutions, examining their benefits, challenges, and the future potential they hold.
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
8. PHP 8.1
Enumerations: RFC Created
04 Dec 2020
25 Nov 2021
03 Feb 2021 Voting started
17 Feb 2021 Voting ended: 44:7
28 Apr 2021 Oxford PHP - April 2021
9. Why we need Enums
How Enums can help
Enums in PHP 8.1
Enum Semantics
Usage Examples
Trying out Enums today
Backwards Compatibility
PHP 8.1: Enums
19. Why we need Enums
function curl_setopt(CurlHandle $handle, int $option, mixed $value) : bool {}
20. curl_setopt($handle, 10003, 'https://example.com');
PHP Error: curl_setopt(): Argument #2 ($option) is not a valid cURL option in … on line …
curl_setopt($handle, 10002, 'https://example.com');
10002 - CURLOPT_URL
curl_setopt($handle, 10004, 'https://example.com');
10004 - CURLOPT_PROXY
Why we need Enums
function curl_setopt(CurlHandle $handle, int $option, mixed $value) : bool {}
21. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {}
}
Why we need Enums
22. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
Why we need Enums
23. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {}
}
$post = new Post();
$post->updateStatus('returned');
Why we need Enums
24. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {}
}
$post = new Post();
$post->updateStatus('returned');
Why we need Enums
25. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {}
}
Why we need Enums
26. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
Why we need Enums
27. class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
Why we need Enums
https://en.wikipedia.org/wiki/Open-closed_principle
29. How Enums Can Help
type PostStatus = "draft" | "pending" | "returned" | "published";
30. How Enums Can Help
type PostStatus = "draft" | "pending" | "returned" | "published";
function updateStatus(status: PostStatus) {}
31. How Enums Can Help
type PostStatus = "draft" | "pending" | "returned" | "published";
function updateStatus(status: PostStatus) {}
32. How Enums Can Help
type PostStatus = "draft" | "pending" | "returned" | "published";
function updateStatus(status: PostStatus) {}
updateStatus("potato");
Argument of type '"potato"' is not assignable to
parameter of type 'PostStatus'.
updateStatus("draft");
✔️
34. How Enums Can Help
enum PostStatus {
DRAFT,
PENDING,
PUBLISHED,
RETURNED,
};
function updateStatus(status: PostStatus) {
}
updateStatus(PostStatus.DRAFT);
35. How Enums Can Help
enum PostStatus {
DRAFT = "draft",
PENDING = "pending",
PUBLISHED = "published",
RETURNED = "draft",
};
function updateStatus(status: PostStatus) {
}
updateStatus(PostStatus.DRAFT);
36. How Enums Can Help
enum PostStatus {
DRAFT = "draft",
PENDING = "pending",
PUBLISHED = "published",
RETURNED = "draft",
};
enum PostStatus {
DRAFT = "draft";
PENDING = "pending";
PUBLISHED = "published";
RETURNED = "draft";
};
38. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
How Enums Can Help
39. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
40. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
41. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public string $status;
public function updateStatus(string $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
42. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public PostStatus $status;
public function updateStatus(string $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
43. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public PostStatus $status;
public function updateStatus(PostStatus $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
44. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public PostStatus $status;
public function updateStatus(PostStatus $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
45. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public PostStatus $status;
public function updateStatus(PostStatus $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(Post::POST_STATUS_PUBLISHED);
How Enums Can Help
46. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public const POST_STATUS_DRAFT = 'draft';
public const POST_STATUS_PENDING = 'pending';
public const POST_STATUS_RETURNED = 'returned';
public const POST_STATUS_PUBLISHED = 'published';
public PostStatus $status;
public function updateStatus(PostStatus $status): void {
if ( $status !== static::POST_STATUS_DRAFT
&& $status !== static::POST_STATUS_PENDING
&& $status !== static::POST_STATUS_RETURNED
&& $status !== static::POST_STATUS_PUBLISHED
) {
throw new InvalidArgumentException('Invalid state');
}
}
}
$post = new Post();
$post->updateStatus(PostStatus::PUBLISHED);
How Enums Can Help
47. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
class Post {
public PostStatus $status;
public function updateStatus(PostStatus $status): void {
}
}
$post = new Post();
$post->updateStatus(PostStatus::PUBLISHED);
How Enums Can Help
48. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
function setIsSponsored(bool $sponsored): void {
}
function isSponsored(): bool {
}
setIsSponsored(true);
setIsSponsored(false);
How Enums Can Help
50. Enums in PHP 8.1
enum Suit {
}
• Enums can have zero or more members
51. Enums in PHP 8.1
enum Suit {
case Clubs;
case Diamonds;
case Spades;
case Hearts;
}
• Enums can have zero or more members
52. Enums in PHP 8.1
enum Suit {
case Clubs;
case Diamonds;
case Spades;
case Hearts;
}
• Enums can have zero or more members
• Enum members are objects
is_object(Suit::Hearts);
// true
53. Enums in PHP 8.1
enum Suit {
case Clubs;
case Diamonds;
case Spades;
case Hearts;
}
• Enums can have zero or more members
• Enum members are objects
var_dump(Suit::Hearts);
// enum(Suit::Hearts)
54. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit {
case Clubs;
case Diamonds;
case Spades;
case Hearts;
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
55. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: int {
case Clubs = 1;
case Diamonds = 2;
case Spades = 3;
case Hearts = 4;
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
56. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
case Clubs = '♣️';
case Diamonds = '♦️';
case Spades = '♠️';
case Hearts = '♥️';
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
57. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = '♣️';
case Diamonds = '♦️';
case Spades = '♠️';
case Hearts = '♥️';
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
58. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = '♣️';
case Diamonds = '♦️';
case Spades = '♠️';
case Hearts = '♥️';
public static function cheer(): void {
echo 'Yay!';
}
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
• May contain static methods
Suit::cheer();
// Yay!
59. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = ' ';
case Diamonds = ' ';
case Spades = ' ';
case Hearts = ' ';
public static function cheer(): void {
echo 'Yay!';
}
public function show(): void {
var_dump($this);
var_dump($this->name);
var_dump(self::Clubs->name);
var_dump($this->value);
var_dump(self::Clubs->value);
}
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
• May contain static methods
• May contain non-static methods
Suit::Clubs->show();
60. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = ' ';
case Diamonds = ' ';
case Spades = ' ';
case Hearts = ' ';
public static function cheer(): void {
echo 'Yay!';
}
public function show(): void {
var_dump($this);
var_dump($this->name);
var_dump(self::Clubs->name);
var_dump($this->value);
var_dump(self::Clubs->value);
}
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
• May contain static methods
• May contain non-static methods
• $this refers to the Enumerated element
Suit::Clubs->show();
enum(AppPlayingCardsSuit::Clubs)
61. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = ' ';
case Diamonds = ' ';
case Spades = ' ';
case Hearts = ' ';
public static function cheer(): void {
echo 'Yay!';
}
public function show(): void {
var_dump($this);
var_dump($this->name);
var_dump(self::Clubs->name);
var_dump($this->value);
var_dump(self::Clubs->value);
}
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
• May contain static methods
• May contain non-static methods
• $this refers to the Enumerated element
• ->name property is the name of the member
Suit::Clubs->show();
enum(AppPlayingCardsSuit::Clubs)
string(5) "Clubs"
string(5) "Clubs"
62. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = ' ';
case Diamonds = ' ';
case Spades = ' ';
case Hearts = ' ';
public static function cheer(): void {
echo 'Yay!';
}
public function show(): void {
var_dump($this);
var_dump($this->name);
var_dump(self::Clubs->name);
var_dump($this->value);
var_dump(self::Clubs->value);
}
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
• May contain static methods
• May contain non-static methods
• $this refers to the Enumerated element
• ->name property is the name of the member
• ->value property is the backed value
Suit::Clubs->show();
enum(AppPlayingCardsSuit::Clubs)
string(5) "Clubs"
string(5) "Clubs"
string(6) "♣️"
string(6) "♣️"
63. Enums in PHP 8.1
namespace AppPlayingCards;
enum Suit: string {
const AWESOME = 'Yes';
case Clubs = ' ';
case Diamonds = ' ';
case Spades = ' ';
case Hearts = ' ';
public static function cheer(): void {
echo 'Yay!';
}
public function show(): void {
var_dump($this);
var_dump($this->name);
var_dump(self::Clubs->name);
var_dump($this->value);
var_dump(self::Clubs->value);
}
}
• Enums can have zero or more members
• Enum members are objects
• Enums can be namespaced and autoloaded
• May contain string|int backed values
• May contain non-duplicated constants
• May contain static methods
• May contain non-static methods
• $this refers to the Enumerated element
• ->name property is the name of the member
• ->value property is the backed value
Suit::Clubs->show();
enum(AppPlayingCardsSuit::Clubs)
string(5) "Clubs"
string(5) "Clubs"
string(6) "♣️"
string(6) "♣️"
64. enum PostStatus {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
Enums in PHP 8.1
Unit Enums
65. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
Enums in PHP 8.1
Unit Enums
66. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
interface UnitEnum {
public static function cases(): array;
}
Enums in PHP 8.1
Unit Enums
67. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
interface UnitEnum {
public static function cases(): array;
}
Enums in PHP 8.1
Unit Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
68. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
interface UnitEnum {
public static function cases(): array;
}
Enums in PHP 8.1
Unit Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
69. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
interface UnitEnum {
public static function cases(): array;
}
Enums in PHP 8.1
Unit Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
PostStatus::cases();
70. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
interface UnitEnum {
public static function cases(): array;
}
Enums in PHP 8.1
Unit Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
array(4) {
[0]=> enum(PostStatus::DRAFT)
[1]=> enum(PostStatus::PENDING)
[2]=> enum(PostStatus::RETURNED)
[3]=> enum(PostStatus::PUBLISHED)
}
PostStatus::cases();
71. enum PostStatus implements UnitEnum {
case DRAFT;
case PENDING;
case RETURNED;
case PUBLISHED;
}
interface UnitEnum {
public static function cases(): array;
}
Enums in PHP 8.1
Unit Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
array(4) {
[0]=> enum(PostStatus::DRAFT)
[1]=> enum(PostStatus::PENDING)
[2]=> enum(PostStatus::RETURNED)
[3]=> enum(PostStatus::PUBLISHED)
}
PostStatus::cases();
72. enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
Backed Enums extend Unit Enums
Backed Enums
Enums in PHP 8.1
73. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
74. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(int|string $value): static;
public static function tryFrom(int|string $value): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
75. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
76. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
77. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
78. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
79. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
80. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
81. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
enum(PostStatus::DRAFT)
82. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
enum(PostStatus::DRAFT)
PostStatus::tryFrom('potato');
PostStatus::from('potato');
83. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
enum(PostStatus::DRAFT)
PostStatus::tryFrom('potato');
PostStatus::from('potato');
84. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
enum(PostStatus::DRAFT)
PostStatus::tryFrom('potato');
// null
PostStatus::from('potato');
Uncaught ValueError: "potato" is not a valid backing value
for enum "PostStatus"
85. enum PostStatus: string implements BackedEnum {
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
interface BackedEnum extends UnitEnum {
public static function from(
int|string $value
): static;
public static function tryFrom(
int|string $value
): ?static;
}
Enums in PHP 8.1
Backed Enums extend Unit Enums
Backed Enums
echo PostStatus::DRAFT->name;
// "DRAFT"
echo PostStatus::DRAFT->value;
// "draft"
PostStatus::tryFrom('draft');
PostStatus::from('draft');
enum(PostStatus::DRAFT)
PostStatus::tryFrom('potato');
// null
PostStatus::from('potato');
Uncaught ValueError: "potato" is not a valid backing value
for enum "PostStatus"
88. Enum Semantics
Enum
Enumerated type that contains a fixed number of members.
A type that is supported as parameter, return, and property type in PHP,
and the type is enforced by PHP itself.
90. Enum Semantics
Enum
Enumerated type that contains a fixed number of members.
Members of an Enum is fixed at the declaration time.
An enumerated member is identical to the same member everywhere.
Enums must not contain state.
91. Enum Semantics
Enumerated types
enum Suit {
case Spades;
case Hearts;
case Clubs;
case Diamonds;
}
function play_card(Suit $suit, string $card) {}
function pick_a_suit(): Suit {
return Suit::Spades;
}
play_card(Suit::Spades, 'A');
var_dump(pick_a_suit());
// enum(Suit::Spades)
92. Enum Semantics
enum Suit {
case Spades;
case Hearts;
case Clubs;
case Diamonds;
}
function play_card(Suit $suit, string $card) {}
function pick_a_suit(): Suit {
return Suit::Spades;
}
play_card(Fruits::Apple);
play_card(Languages::English);
play_card('potato');
Fatal error: Uncaught TypeError: play_card(): Argument #1
($suit) must be of type Suit, string given
Enumerated types
94. Enum Semantics
enum Suit {
case Spades;
case Hearts;
case Clubs;
case Diamonds;
}
Fixed Members
Suit::Spades === Suit::Spades
95. Enum Semantics
enum Suit {
case Spades;
case Hearts;
case Clubs;
case Diamonds;
}
Fixed Members
enum RussianSuit extends Suit {}
Parse error: syntax error, unexpected token "extends",
expecting "{"
96. Enum Semantics
enum Suit {
case Spades;
case Hearts;
case Clubs;
case Diamonds;
private string $foo;
}
No Properties Allowed
Fatal error: Enums may not include properties
97. Enum Semantics
Backed Enums must assign values for all cases
enum HTTPMethods: string {
case GET;
case POST;
}
Fatal error: Case GET of backed enum HTTPMethods must have a value
98. Enum Semantics
Enum cases and values must be unique
Fatal error: Cannot redefine class
constant Test::FOO
enum Test {
case FOO;
case FOO;
}
enum Test: string {
case FOO = 'baz';
case BAR = 'baz';
}
Fatal error: Duplicate value in
enum Test for cases FOO and BAR
99. Enum Semantics
Class Semantics
namespace FooBar;
enum PostStatus: string implements EntityStatues {
use TestTrait;
case DRAFT = 'draft';
case PENDING = 'pending';
case RETURNED = 'returned';
case PUBLISHED = 'published’;
public static function showOff(): void {
echo __CLASS__ . static::class;
}
}
• Supports namespaces
• Supports traits
• Supports autoloading
• Supports magic constants
• Supports instanceof
• Supports methods
101. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
102. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
103. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
104. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
105. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
106. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
} $stmt = $pdo->prepare("
SELECT *
FROM posts
WHERE post_status=?");
$stmt->execute([
PostStatus::PUBLISHED->value
]);
$post = $stmt->fetch();
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
107. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
} $stmt = $pdo->prepare("
SELECT *
FROM posts
WHERE post_status=?");
$stmt->execute([
PostStatus::PUBLISHED->value
]);
$post = $stmt->fetch();
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
108. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
$sql = "
INSERT INTO
posts (id, title, post_status)
VALUES
(:id, :title, :post_status)";
$stmt= $pdo->prepare($sql);
$stmt->execute([
'id' => $post->getId(),
'title' => $post->getTitle(),
'post_status' => $post->getStatus()->value,
]);
109. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
}
$sql = "
INSERT INTO
posts (id, title, post_status)
VALUES
(:id, :title, :post_status)";
$stmt= $pdo->prepare($sql);
$stmt->execute([
'id' => $post->getId(),
'title' => $post->getTitle(),
'post_status' => $post->getStatus()->value,
]);
110. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
public function updateStatus(
PostStatus $status
): void {
}
}
$result = [
'id' => 42,
'title' => 'PHP Enums',
'post_status' => 'published',
];
$post = new Post(
$result['id'],
$result['title']
);
$post->updateStatus(
PostStatus::from($result['post_status'])
);
111. Usage Examples
enum PostStatus: string {
case DRAFT = 'draft';
case PENDING = 'pending’;
case RETURNED = 'returned';
case PUBLISHED = 'published';
}
class Post {
private int $id;
private string $title;
private PostStatus $status;
public function __construct(
int $id,
string $title,
PostStatus $status
) {
// ...
}
public function getStatus(): PostStatus {
return $this->status;
}
public function updateStatus(
PostStatus $status
): void {
}
}
$result = [
'id' => 42,
'title' => 'PHP Enums',
'post_status' => 'published',
];
$post = new Post(
$result['id'],
$result['title']
);
$post->updateStatus(
PostStatus::from($result['post_status'])
);
117. Backwards Compatibility
Enums is a new syntax
Enums is a new syntax introduced in PHP 8.1, and not
supported in older PHP versions.
Parse error: syntax error, unexpected identifier "PostStatus"
118. Backwards Compatibility
User-land PHP implementations
https://github.com/myclabs/php-enum
use MyCLabsEnumEnum;
class PostStatus extends Enum {
private const DRAFT = 'draft';
private const PENDING = 'pending';
private const RETURNED = 'returned';
private const PUBLISHED = 'published';
}