Laravel

PHP OOP Essentials

Classes, objects, visibility, inheritance, traits, interfaces, abstract classes, static members

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

What is a class in PHP?

Câu trả lời

A class is a blueprint that defines the properties and methods of an object. It encapsulates data (properties) and behaviors (methods) in a reusable structure. Classes allow creating multiple instances (objects) with the same structure but different values.

2

How to create an instance of a class in PHP?

Câu trả lời

The 'new' keyword allows instantiating a class and creating an object. For example, 'new User()' creates a new instance of the User class. If the class has a constructor, arguments can be passed directly: 'new User("John")', which automatically calls __construct() with the provided parameters.

3

What is the difference between a 'public' and 'private' property in PHP?

Câu trả lời

A 'public' property is accessible from outside the class (via the object or in child classes), while a 'private' property is accessible only from the class that defines it. Using 'private' encapsulates data and prevents direct access, forcing the use of getters/setters to control data manipulation. This is a recommended practice to protect data integrity.

4

What is the role of 'protected' visibility in PHP?

5

How to define a constructor in PHP?

+17 câu hỏi phỏng vấn

Nắm vững Laravel 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í