200+ PHP Interview Questions Flashcards

1
Q

Q17. What is the difference between multiple and multilevel inheritance?

A

Multiple inheritance means a class has more than one parent. It can use methods and properties from all parents, but sometimes there are conflicts (diamond problem).

Multilevel inheritance is a chain. One class inherits from another, then another. It gets all properties from previous classes, and there is no diamond problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q17.a. What are traits in PHP?

A

Traits are a way to reuse code in different classes. They are like small pieces of a class that you can “copy” into many classes.

Traits are not classes - they cannot be used alone, only inside a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q17.b. Why use traits?

A

To share methods between different classes.
To avoid duplicate code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q17.c. Problems with traits in PHP

A
  1. Method conflicts - if two traits have the same method name, you must choose which one to use.

use TraitA, TraitB { TraitA::method insteadof TraitB; }

  1. No real inheritance - You cannot override them, and they do not support polymorphism
  2. Hard to read code - uf class uses many traits, it is difficult to understand where methods come from.
  3. Overuse - Some developers use traits instead of inheritance or composition, making code messy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q17.d. Best use of traits?

A

Traits are good for reusing code (like logging or caching), but they do not replace inheritance and composition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q18. What is a Closure in PHP and why do we use it?

A

Closure is the class, which represents anonymous functions. This means that you can store the function to any variable and this variable will be the object of the Closure class.
- Can be passed as arguments to other functions
- Can access variables from outside their scope
- Useful for short, reusable logic (sorting, filtering, callbacks)

Closures are common in event handling, function programming and asynchronous tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q19.a. What is session and how it works?

A

Session is a way to store user data on the server side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q19.b. What is trigger?

A

Triggers are used to execute a set of SQL statements when a specific event occurs.

  • To automate actions (logging, validation)
  • To update related tables (update stock after a sale)

Triggers are useful, but too many triggers can slow down performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q19.c. What is View?

A

Views are virtual tables that display data from one or more tables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q19.d. What is GET and POST?

A

GET and POST are HTTP methods used to send data to a server.

GET:
- Data is sent in the URL
- Often used for retrieving data (displaying a webpage)
- Limit on the amount of data you can send
- Not secure for sensitive data (like password)

POST:
- Data is sent in the body of the request
- Used for sending large amounts of data
- More secure then GET for sensitive data
- No data sie limit like GET

In summary, GET is for getting data, and POST is for sending data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly