Symfony

Modern PHP (8.1+)

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

20 câu hỏi phỏng vấn·
Junior
1

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

Câu trả lời

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+?

Câu trả lời

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+?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Symfony cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí