Explore topic-wise MCQs in Php.

This section includes 194 Mcqs, each offering curated multiple-choice questions to sharpen your Php knowledge and support exam preparation. Choose a topic below to get started.

101.

*/*_Which one of the following methods in the exception class, is used to get a nested exception object??

A. getPrevious()
B. getCode()
C. getFile()
D. getLine()
Answer» B. getCode()
102.

*/*_Which one of the following method is invoked when an undefined method is called by client code??

A. __get()
B. __isset()
C. __unset()
D. __call()
Answer» E.
103.

%_PHP recognises constructors by the name . . . . ._%

A. _construct
B. __construct
C. __constructor
D. _constructor
Answer» C. __constructor
104.

%_Which one of the following methods in the exception class, is used to get a nested exception object?_%

A. getPrevious()
B. getCode()
C. getFile()
D. getLine()
Answer» B. getCode()
105.

%_Which one of the following method is invoked when an undefined method is called by client code?_%

A. __get()
B. __isset()
C. __unset()
D. __call()
Answer» E.
106.

%_Which function is used to determine whether the variable’s value is either TRUE or FALSE?_%

A. boolean()
B. is_boolean()
C. bool()
D. is_bool()
Answer» E.
107.

%_Which keyword is used to declare a constant property?_%

A. const
B. con
C. constant
D. _constant
Answer» B. con
108.

%_Which one of the following keywords is used to define an abstract class?_%

A. extends
B. implements
C. abstract
D. new
Answer» D. new
109.

%_What should be used to refer to a method in the context of a class rather than an object you use?_%

A. ->
B. __
C. $
D. ::
Answer» E.
110.

%_Which keyword is used to access a static method or property from within the same class(rather than from child)?_%

A. static
B. strat
C. self
D. set
Answer» D. set
111.

%_Which method is used to tweak an object’s cloning behavior?_%

A. clone()
B. __clone()
C. _clone
D. object_clone()
Answer» C. _clone
112.

_ Which one of the following is the right way to clone an object?$?

A. _clone(targetObject);
B. destinationObject = clone targetObject;
C. destinationObject = _clone(targetObject);
D. destinationObject = clone(targetObject);
Answer» C. destinationObject = _clone(targetObject);
113.

_ In the PHP code given below, what is/are the properties?$?

A. echo “This is an example”;
B. public $name;
C. class Example
D. function sample()
Answer» C. class Example
114.

_ PHP recognizes constructors by the name_________$?

A. classname()
B. _construct()
C. function _construct()
D. function __construct()
Answer» E.
115.

_ Which one of the following is the right way to invoke a method?$?

A. $object->methodName();
B. object->methodName();
C. object::methodName();
D. $object::methodName();
Answer» B. object->methodName();
116.

_ The practice of creating objects based on predefined classes is often referred to as.$?

A. class creation
B. object creation
C. object instantiation
D. class instantiation
Answer» E.
117.

_ Which class accepts a class name or an object reference and returns an array of interface name?$?

A. class_implements()
B. is_subclass()
C. is_subclass_of()
D. class_interface()
Answer» B. is_subclass()
118.

_ PHP 4 did not support instanceof. Instead, which function did it provide?$?

A. is()
B. get_class()
C. is_a()
D. is_the()
Answer» D. is_the()
119.

_ Which one of the following statements is true for require() and require_once()?$?

A. They are functions
B. They are statements
C. They’ll not work if the () is not present
D. They can not be used to require files
Answer» C. They‚Äö√Ñ√¥ll not work if the () is not present
120.

_ Which of the following can you place inside a namespace?1. classes2. functions3. variables$?

A. 1
B. 2
C. 3
D. All of the mentioned
Answer» E.
121.

_ Inheritance in class diagrams is depicted by________$?

A. single-headed empty arrow
B. single-headed filled arrow
C. double-headed empty arrow
D. double-headed filled arrow
Answer» B. single-headed filled arrow
122.

_ If the diamond is filled it depicts which relationship?$?

A. Strong Aggregation
B. Composition
C. Abstraction
D. Inheritance
Answer» C. Abstraction
123.

_ In a class diagram the class is divided into three sections, what is displayed in the first section?$?

A. Class Attributes
B. Class Declaration
C. Class Name
D. Class Functions
Answer» D. Class Functions
124.

_ ________ code makes change easier because the impact of altering an implementation will be localized to the component being altered.$?

A. Orthogonal
B. Cohesion
C. Coupling
D. Balancing
Answer» B. Cohesion
125.

_The result of below statements will be:$str = ""Hello fri3nd, you're feeling happy today?”;echo str_word_count($str);$?

A. 7
B. 6
C. 5
D. 4
Answer» B. 6
126.

_What will be the output of the following PHP codeclass Person { function getName() { return "Bob"; } function getAge() { return 44; } function __toString() { $desc = $this->getName(); $desc .= " (age ".$this->getAge().")"; return $desc; }}$person = new Person();print $person;$?

A. Object Not Found
B. PHP Catchable fatal error
C. BOB (age 44)
D. BOB
Answer» D. BOB
127.

_Which version of PHP introduced the concept called late static binding?$?

A. PHP 4
B. PHP 5
C. PHP 5.1
D. PHP 5.3
Answer» E.
128.

_Which one of the following method is invoked when a value is assigned to an undefined property?$?

A. __get()
B. __set()
C. __isset()
D. __call()
Answer» C. __isset()
129.

_If you omit the visibility keyword in your method declaration, by default the method will be declared as.$?

A. public
B. private
C. protected
D. friendly
Answer» B. private
130.

_Which version of PHP allows you to define constant properties within a class?$?

A. PHP 4
B. PHP 4.1
C. PHP 4.3
D. PHP 5
Answer» E.
131.

_Which one of the following class can not be instantiated?$?

A. inherited class
B. abstract class
C. constant class
D. every class
Answer» C. constant class
132.

_What will be the output of the following PHP code?$?

A. bool(true)
B. bool(false)
C. error
D. none of the above
Answer» B. bool(false)
133.

_Which version of PHP introduced the static keyword?$?

A. PHP 4
B. PHP 5
C. PHP 5.2
D. PHP 5.3
Answer» C. PHP 5.2
134.

_If your object must inherit behavior from a number of sources you must use a/an$?

A. Interface
B. Object
C. Abstract class
D. Static class
Answer» B. Object
135.

_Which version of PHP introduced the advanced concepts of OOP?$?

A. PHP 4
B. PHP 5
C. PHP 5.3
D. PHP 6
Answer» C. PHP 5.3
136.

_Which one of the following keyword is used to inherit our subclass into a superclass?$?

A. extends
B. implements
C. inherit
D. include
Answer» B. implements
137.

_Which of the following statements is/are true about Constructors in PHP?1. PHP 4 introduced class constructors.2. Constructors can accept parameters.3. Constructors can call class methods or other functions.4. Class constructors can call on other constructors.$?

A. 2 and 4
B. All of the mentioned
C. None of the mentioned
D. 2, 3 and 4
Answer» C. None of the mentioned
138.

_Which one of the following is the right way to call a class constant, given that the class is mathFunction?$?

A. echo PI;
B. echo mathFunction->PI;
C. echo mathFunction::PI;
D. echo mathFunction=PI;
Answer» D. echo mathFunction=PI;
139.

_Which of the following term originates from the Greek language that means “having multiple forms,” defines OOP’s ability to redefine, a class’s characteristics?$?

A. Abstraction
B. Polymorphism
C. Inheritance
D. Differential
Answer» C. Inheritance
140.

_Which one of the following function should I use to find the parent class of a class?$?

A. get_parent_class()
B. parent_class()
C. class_parent()
D. get_class_parent()
Answer» B. parent_class()
141.

_Which one of the following will you use to check the class of an object?$?

A. class()
B. _class()
C. class_check()
D. get_class()
Answer» E.
142.

_Which one of the following statements is true for include_once() and require_once()?$?

A. Both are exactly the same
B. include_once is used for files where as require_once() is not
C. Both Handle the errors in the same way
D. Both do not handle the errors in the same way
Answer» E.
143.

_Till which version of PHP, developers were forced to name their files in a global context?$?

A. PHP 4
B. PHP 5
C. PHP 5.2
D. PHP 5.3
Answer» E.
144.

_Which one of the following is displayed in the third section of the class diagram?$?

A. Operations
B. Inheritance
C. Abstraction
D. Coupling
Answer» B. Inheritance
145.

_Which relationship is illustrated by a line that begins with an unfilled diamond?$?

A. Composition
B. Abstraction
C. Aggregation
D. Inheritance
Answer» D. Inheritance
146.

_UML stands for?$?

A. unified mailing language
B. unified modeling logo
C. undefined modeling language
D. unified modeling language
Answer» E.
147.

_______ occurs when discrete parts of a system’s code are tightly bound up with one another so that a change in one part necessitates changes in the others.$?

A. Loose Coupling
B. Tight Coupling
C. Co-relation
D. Balancing
Answer» C. Co-relation
148.

Which keyword precedes a method name?$?

A. method
B. function
C. public
D. protected
Answer» C. public
149.

Inheritance is the means by which one or more classes can be derived from a/an ___ class.$?

A. base
B. abstract
C. null
D. predefined
Answer» B. abstract
150.

A mutator method is also called as.$?

A. Setter
B. Accessor
C. Getter
D. Destructor
Answer» B. Accessor