Q
Which magic method is called when an undefined property is accessed in PHP?

Answer & Solution

Answer: Option A
Solution:
The __get() magic method in PHP is called when an undefined property is accessed (read) from outside the class. It allows for custom behavior when accessing inaccessible or undefined properties.
Related Questions on Average

What is an object in PHP?

A). A class method

B). A function parameter

C). An instance of a class

D). A variable name

What is the purpose of the interface keyword in PHP?

A). To define a class that cannot be instantiated

B). To define a contract for classes to implement

C). To define a blueprint for objects

D). To prevent a class from being inherited

Which method is automatically called when an object is destroyed in PHP?

A). __delete()

B). __destroy()

C). __dispose()

D). __destruct()

Which OOP concept allows a class to inherit from multiple classes?

A). Inheritance

B). Encapsulation

C). Polymorphism

D). Multiple inheritance

Which concept allows a method in a subclass to have the same name as a method in its superclass?

A). Encapsulation

B). Inheritance

C). Polymorphism

D). Abstraction

Which keyword is used for inheritance in PHP?

A). inherit

B). extends

C). inherit_from

D). inherits

What is the visibility of properties or methods declared as private in PHP?

A). Public

B). Protected

C). Private

D). Accessible only within the class

What is the purpose of the static keyword in PHP?

A). To access properties or methods without instantiating the class

B). To prevent a class from being instantiated

C). To define constants

D). To access superclass methods

Which keyword is used to create a class in PHP?

A). new

B). object

C). define

D). class

Which keyword is used to access properties or methods within the same class in PHP?

A). public

B). protected

C). private

D). $this