card for PHP Advance level that shoul include examples too with definitions Flashcards

1
Q

What is the purpose of namespaces in PHP?

A

Namespaces are used to encapsulate items such as classes, interfaces, functions, and constants to avoid name collisions.

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

True or False: PHP supports multiple inheritance.

A

False. PHP does not support multiple inheritance but allows interfaces to achieve similar functionality.

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

Fill in the blank: The PHP function _______ is used to include files.

A

include

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

What is the difference between ‘include’ and ‘require’ in PHP?

A

‘include’ generates a warning if the file cannot be found, while ‘require’ generates a fatal error.

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

What is a closure in PHP?

A

A closure is an anonymous function that can capture variables from its surrounding scope.

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

Provide an example of a closure in PHP.

A

$greet = function($name) { return ‘Hello, ‘ . $name; };

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

What does the ‘final’ keyword do in a class definition?

A

The ‘final’ keyword prevents a class from being inherited.

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

What is the purpose of the ‘static’ keyword in PHP?

A

The ‘static’ keyword is used to declare properties and methods that belong to the class itself rather than to any specific object instance.

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

True or False: Traits in PHP allow for code reuse in single inheritance.

A

True. Traits enable code reuse in classes that are not related through inheritance.

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

What is the purpose of the ‘abstract’ keyword in PHP?

A

The ‘abstract’ keyword is used to define a class that cannot be instantiated and may contain abstract methods that must be implemented in derived classes.

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

What is an interface in PHP?

A

An interface defines a contract that classes must follow, specifying methods that must be implemented without providing the implementation.

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

Provide an example of an interface in PHP.

A

interface Animal { public function makeSound(); }

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

What does the ‘instanceof’ operator do in PHP?

A

The ‘instanceof’ operator checks whether an object is an instance of a specific class or interface.

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

What is the purpose of the ‘try-catch’ block in PHP?

A

The ‘try-catch’ block is used for exception handling, allowing you to catch and handle exceptions that occur during execution.

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

True or False: PHP supports operator overloading.

A

False. PHP does not support operator overloading.

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

What is PDO in PHP?

A

PDO (PHP Data Objects) is a database access layer providing a uniform method of access to multiple databases.

17
Q

What does the ‘bindParam’ method do in PDO?

A

‘bindParam’ binds a parameter to a specified variable name and allows for the execution of prepared statements.

18
Q

What is the purpose of Composer in PHP?

A

Composer is a dependency manager for PHP, allowing you to manage libraries and packages for your projects.

19
Q

Provide an example of how to install a package using Composer.

A

composer require vendor/package-name

20
Q

What is a PSR in PHP?

A

PSR stands for PHP Standard Recommendation, which provides guidelines for coding standards and best practices in PHP.

21
Q

What is the purpose of the ‘autoload’ feature in Composer?

A

The ‘autoload’ feature automatically loads classes without requiring manual ‘include’ or ‘require’ statements.

22
Q

What does the ‘return’ statement do in a function?

A

The ‘return’ statement ends the function execution and returns a value to the calling code.

23
Q

What are magic methods in PHP?

A

Magic methods are special methods that start with double underscores (__), allowing you to define behavior for object instantiation, property access, and more.

24
Q

Provide an example of a magic method in PHP.

A

public function __construct() { // initialization code }

25
Q

What is the purpose of the ‘serialize’ function in PHP?

A

The ‘serialize’ function converts a PHP value into a storable representation, typically for saving to a file or database.

26
Q

What does the ‘json_encode’ function do?

A

The ‘json_encode’ function converts a PHP value into a JSON format string.