Symfony

Modern PHP (8.1+)

Enums, readonly properties, attributes, promoted properties, named arguments, union types, strict typing, match expression

20 preguntas de entrevista·
Junior
1

What is the correct syntax to declare an enumeration (enum) in PHP 8.1+?

Respuesta

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.

2

What is a backed enum in PHP 8.1+?

Respuesta

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.

3

How to declare a readonly property in PHP 8.1+?

Respuesta

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.

4

What is the main constraint of a readonly property in PHP 8.1+?

5

What is constructor property promotion in PHP 8.0+?

+17 preguntas de entrevista

Domina Symfony para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis