Olete.in
Articles
Mock Tests
🧪 PHP MCQ Quiz Hub
PHP Mcq Set 1
Choose a topic to test your knowledge and improve your PHP skills
1. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _____
Polymorphism
Inheritance
Encapsulation
Abstraction
2. 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?
Abstraction
Polymorphism
Inheritance
Differential
3. The practice of creating objects based on predefined classes is often referred to as _____
class creation
object creation
object instantiation
class instantiation
4. Which one of the following property scopes is not supported by PHP?
friendly
final
public
static
5. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
$obj = new $foo;
$obj = new foo;
$obj = new foo ();
obj = new foo ();
6. Which one of the following is the right way to define a constant?
constant PI = “3.1415”;
const $PI = “3.1415”;
constant PI = ‘3.1415’;
const PI = ‘3.1415’;
7. Which one of the following is the right way to call a class constant,given that the class is mathFunction?
echo PI;
echo mathFunction->PI;
echo mathFunction::PI;
echo mathFunction=PI;
8. Which one of the following is the right way to invoke a method?
$object->methodName();
object->methodName();
object::methodName();
$object::methodName();
9. Which method scope prevents a method from being overridden by a subclass?
Abstract
Protected
Final
Static
10. PHP recognizes constructors by the name _____
classname()
_construct()
function _construct()
function __construct()
11. Which version of PHP introduced the instanceof keyword?
PHP 4
PHP 5
PHP 5.3
PHP 6
12. Which one of the following functions is used to determine whether a class exists?
exist()
exist_class()
class_exist()
__exist()
13. Which one of the following functions is used to determine object type?
obj_type()
type()
is_a()
is_obj()
14. Which one of the following keyword is used to inherit our subclass into a superclass?
extends
implements
inherit
include
15. Which keyword is used to refer to properties or methods within the class itself?
private
public
protected
$this
16. Which keyword allows class members (methods and properties) to be used without needing to instantiate a new instance of the class?
protected
final
static
private
17. Which version of PHP introduced the advanced concepts of OOP?
PHP 4
PHP 5
PHP 5.3
PHP 6
18. Which one of the following is the right way to clone an object?
clone(targetObject);
destinationObject = clone targetObject;
destinationObject = _clone(targetObject);
destinationObject = clone(targetObject);
19. If one intends to create a model that will be assumed by a number of closely related objects,which class must be used?
Normal class
Static class
Abstract class
Interface
20. If your object must inherit behavior from a number of sources you must use a/an
Interface
Object
Abstract class
Static class
21. Which method is used to tweak an object’s cloning behavior?
clone()
__clone()
_clone
object_clone()
22. Which feature allows us to call more than one method or function of the class in single instruction?
Typecasting
Method Including
Method adding
Method chaining
23. Which magic method is used to implement overloading in PHP?
__call
__invoke
__wakeup
_unset
24. How many error levels are available in PHP?
14
15
16
17
25. What is the description of Error level E_ERROR?
Fatal run-time error
Near-fatal error
Compile-time error
Fatal Compile-time error
26. Which version of PHP introduced E_STRICT Error level?
PHP 4
PHP 5
PHP 5.2
PHP 5.3
27. Which character does the error_reporting directive use to represent the logical operator NOT?
/
!
~
^
28. Say you want to report error concerned about fatal run-time,fatal compile-time error and core error which statement would you use?
error_reporting = E_ALL
error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR
error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR
29. Which version introduced the function error_get_last()?
PHP 4
PHP 5
PHP 5.2
PHP 5.3
30. Which of the following statements causes PHP to disregard repeated error messages that occur within the same file and on the same line?
ignore_repeated_errors
ignore_repeat_error
repeatedly_ignore_error
repeated_error_ignore
31. Which function initializes the constants necessary for using the openlog(),clodelog(),and syslog() functions?
define_variable()
define_log_variable()
log_variable()
define_syslog_variable()
32. Which logging option’s description is if an error occurs when writing to the syslog, send output to the system console?
LOG_CONS
LOG_NDELAY
LOG_ODELAY
LOG_PERROR
33. Which function is responsible for sending a custom message to the system log?
systemlog()
syslog()
log_system()
sys_log()
34. Which version of PHP was added with Exception handling?
PHP 4
PHP 5
PHP 5.3
PHP 6
35. How many methods are available for the exception class?
5
6
7
8
36. Which version added the method getPrevious()?
PHP 4
PHP 5
PHP 5.1
PHP 5.3
37. Which of the following statements invoke the exception class?
throws new Exception();
throw new Exception();
new Exception();
new throws Exception();
38. Which one of the following is the right description for the method getMessage()?
Returns the message if it is passed to the constructor
Returns the message if it is passed to the class
Returns the message if it is passed to the file
Returns the message if it is passed to the object
39. You can extend the exception base class,but you cannot override any of the preceding methods because the are declared as_________
protected
final
static
private
40. What does SPL stand for?
Standard PHP Library
Source PHP Library
Standard PHP List
Source PHP List
41. How many predefined exceptions does SPL provide access to?
13
14
15
16
42. How many types of filtering are present in PHP?
3
2
4
None
43. Which one of the following filter is used to filter several variables with the same or different filters?
filter_var_array()
filter_var()
filter_input
filter_input_array
44. Which one of the following does not describe a validating filter?
Are used to allow or disallow specific characters in a string
Are used to validate user input
Strict format rules
Returns the expected type on success or FALSE on failure
45. Which one of the following filter checks if the variable of the specified type exists?
filter_has_var
filter_var
filter_id
filter_var_array
46. Which one of the following regular expression matches any string containing zero or one p?
p+
p*
P?
p#
47. [:alpha:] can also be specified as ________
[A-Za-z0-9]
[A-za-z]
[A-z]
[a-z]
48. How many functions does PHP offer for searching strings using POSIX style regular expression?
7
8
9
10
49. POSIX implementation was deprecated in which version of PHP?
PHP 4
PHP 5
PHP 5.2
PHP 5.3
50. POSIX stands for _________
Portable Operating System Interface for Unix
Portable Operating System Interface for Linux
Portative Operating System Interface for Unix
Portative Operating System Interface for Linux
Submit