
Modern PHP (8.1+)
Enums, readonly properties, attributes, promoted properties, named arguments, union types, strict typing, match expression
1What is the correct syntax to declare an enumeration (enum) in PHP 8.1+?
What is the correct syntax to declare an enumeration (enum) in PHP 8.1+?
Answer
In PHP 8.1+, enumerations are declared using the enum keyword followed by the name and possible cases within braces. Enums allow defining a type with a finite set of possible values, which improves type safety and makes code more expressive. Backed enums can have associated string or int values.
2What is a backed enum in PHP 8.1+?
What is a backed enum in PHP 8.1+?
Answer
A backed enum is an enumeration where each case is associated with a scalar value (string or int). This value enables serialization and database storage. The syntax uses a colon after the enum name to specify the backing type, then each case receives a value with the equals sign.
3How to declare a readonly property in PHP 8.1+?
How to declare a readonly property in PHP 8.1+?
Answer
The readonly modifier is placed before the property type. A readonly property can only be initialized once, either in the declaration or in the constructor. Once set, its value cannot be changed, which guarantees the immutability of that property.
What is the main constraint of a readonly property in PHP 8.1+?
What is constructor property promotion in PHP 8.0+?
+17 interview questions
Other Symfony interview topics
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Data Validation
Dependency Injection & Services
Security & Authentication
Doctrine Advanced
API Platform
Serializer Component
Events & Event Subscribers
Console & Commands
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Master Symfony for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free