PHP MCQ Questions & Answers

PHP MCQ With Answers

 

1. PHP Stands for

A. Php Hypertext Processor
B. Php Hypertext Preprocessor
C. Php Hypermarkup Preprocessor
D. Php Hyper Markup Processor

Show Answer
B. Php Hypertext Preprocessor

 

2. PHP is _______ scripting language.

A. Server-side
B. Clint-side
C. Middle-side
D. Out-side

Show Answer
A. Server-side

 

3. PHP scripts are executed on _________

A. ISP Computer
B. Client Computer
C. Server Computer
D. It depends on PHP scripts

Show Answer
C. Server Computer

 

4. PHP Scripts starts with ________ 

A. <php> … </php>
B. <?php …. ?>
C. ?php … ?php
D. <p> … </p>

Show Answer
B. <?php …. ?>

 

5. Which of the following statements prints in PHP?

A. Out
B. Write
C. Echo
D. Display

Show Answer
C. Echo

 

6. In PHP, each statement must be end with ______

A. . (dot)
B. ; (semicolon)
C. / (slash)
D. : (colon)

Show Answer
B. ; (semicolon)

 

7. In PHP Language variables name starts with _____

A. ! (Exclamation)
B. & (Ampersand)
C. * (Asterisk)
D. $ (Dollar)

Show Answer
D. $ (Dollar)

 

8. In PHP Language variables are case sensitive

A. True
B. False
C. Depends on website
D. Depends on server

Show Answer
A. True

 

9. In PHP a variable needs to be declare before assign

A. True
B. False
C. Depends on website
D. Depends on server

Show Answer
B. False

 

10. Which of the following is not the scope of Variable in PHP?

A. Local
B. Global
C. Static
D. Extern

Show Answer
D. Extern

 

11. What is the use of strlen( ) function in PHP? 

A. It returns the type of a string
B. It returns the value of a string
C. It returns the length of a string
D. It returns the subset value of a string

Show Answer
C. It returns the length of a string

 

12. Which of the following is the Concatenation Operator in PHP?

A. + (Plus)
B. . (dot)
C. & (Ampersand)
D. % (Percentage)

Show Answer
B. . (dot)

 

13. Which of the following is not PHP Loops?

A. while
B. do while
C. for
D. do for

Show Answer
D. do for

 

14. What is the use of strpos( ) function in PHP?

A. Search for a number within a string
B. Search for a Spaces within a string
C. Search for a character/text within a string
D. Search for a Capitalized string/text with in a string

Show Answer
C. Search for a character/text within a string

 

15. Where setcookie( ) function must appear in PHP?

A. Before tag
B. After tag
C. In tag
D. Anywhere

Show Answer
A. Before tag

 

16. What does the hash (#) sign mean in PHP?

A. It indicates lines that are commented out.
B. It indicates variable declaration.
C. It indicates function declaration.
D. No uses in PHP.

Show Answer
A. It indicates lines that are commented out.

 

17. How to define a variable in PHP?

A. $variable_name = value
B. $variable_name = value;
C. $variable_name == value;
D. $variable_name as value;

Show Answer
B. $variable_name = value;

 

18. The uses of strcmp( ) function in PHP?

A. It compare strings including case
B. It compare strings excluding case
C. It compare strings only Uppercase
D. It compare strings only lowercase

Show Answer
A. It compare strings including case

 

19. What will be the result of combining a string with another data type in PHP?

A. int
B. float
C. string
D. double

Show Answer
C. string

 

20. Data for a cookie stored in _________ in PHP?

A. In ISP Computer
B. In User’s Computer
C. In Server Computer
D. It depends on PHP Coding

Show Answer
B. In User’s Computer

 

21. PHP is a ______ typed language.

A. User
B. Loosely
C. Server
D. System

Show Answer
B. Loosely

 

22. What does fopen() function do in PHP?

A. It used to open files in PHP
B. It used to open Remote Server
C. It used to open folders in PHP
D. It used to open Remote Computer

Show Answer
A. It used to open files in PHP

 

23. Where session_start() function must appear in PHP?

A. Anywhere
B. With <html> tag
C. After <html> tag
D. Before <html> tag

Show Answer
D. Before <html> tag

 

24. What does the PHP Interpreter do?

A. It translates User Language to System Language
B. It creates connection between ISP & Server
C. It processes the HTML and PHP files
D. All of these

Show Answer
C. It processes the HTML and PHP files

 

25. Which of the following is used to add comments in PHP?

A. //
B. /* … */
C. & … &
D. Only A & B

Show Answer
D. Only A & B

 

26. What does sprintf() function do in PHP?

A. it sends output to a variable
B. it prints the output of program
C. it sends output to a variable converting into string
D. it prints the output of program converting into string

Show Answer
A. it sends output to a variable

 

27. Variables are case-sensitive in PHP?

A. True
B. False

Show Answer
A. True

 

28. Which function displays the information about PHP?

A. info()
B. sysinfo()
C. phpinfo()
D. php_info()

Show Answer
C. phpinfo()

 

29. What does isset() function do in PHP?

A. There is no such function in PHP
B. It checks whether variable is set or not
C. It checks whether variable is free or not
D. It checks whether variable is string or integer

Show Answer
B. It checks whether variable is set or not

 

30. . How PHP files can be accessed?

A. Through Web Browser
B. Through HTML files
C. Through Web Server
D. All of Above

Show Answer
C. Through Web Server

 

31. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo? 

a) $obj = new $foo;
b) $obj = new foo;
c) $obj = new foo ();
d) obj = new foo ();

Show Answer
c) $obj = new foo ();

 

32. Which one of the following is the right way to define a constant?

a) constant PI = “3.1415”;
b) const $PI = “3.1415”;
c) constant PI = ‘3.1415’;
d) const PI = ‘3.1415’;

Show Answer
d) const PI = ‘3.1415’;

 

33. Which of the following statements is/are true about Constructors in PHP?
i) PHP 4 introduced class constructors.
ii) Constructors can accept parameters.
iii) Constructors can call class methods or other functions.
iv) Class constructors can call on other constructors.

a) ii) and iii)
b) All of the mentioned
c) None of the mentioned
d) ii), iii) and iv)

Show Answer
b) All of the mentioned

 

34. PHP recognizes constructors by the name_________

a) classname()
b) _construct()
c) function _construct()
d) function __construct()

Show Answer
b) _construct()

 

35. Which version of PHP introduced the instanceof keyword?

a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

Show Answer
b) PHP 5

 

36. Which one of the following functions is used to determine whether a class exists?

a) exist()
b) exist_class()
c) class_exist()
d) __exist()

Show Answer
c) class_exist()

 

37. In the PHP code given below, what is/are the properties?
<?php
    class Example 
    {
        public $name;
        function Sample()
        {
            echo "This is an example";
        }
    } 
?>

a) echo “This is an example”;
b) public $name;
c) class Example
d) function sample()

Show Answer
b) public $name;

 

38. Which keyword is used to refer to properties or methods within the class itself?

a) private
b) public
c) protected
d) $this

Show Answer
d) $this 

 

39. Which keyword allows class members (methods and properties) to be used without needing to instantiate a new instance of the class?

a) protected
b) final
c) static
d) private

Show Answer
c) static

 

40. 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);

Show Answer
b) destinationObject = clone targetObject;

 

41. Which method is used to tweak an object’s cloning behavior?

a) clone()
b) __clone()
c) _clone
d) object_clone()

Show Answer
b) __clone()

 

42. 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

Show Answer
c) Class Name

 

43. + is the visibility code for?

a) Public
b) Private
c) Protected
d) Friendly

Show Answer
a) Public

 

44. The keyword used to work with static properties in static method is——

a)static
b)abstract
c)self
d)final

Show Answer
a)static

 

45. The operator used to find whether an object is instantiated is called as—–

a)relational operator
b)arithmetic operator
c)instance of operator
d)logical operator

Show Answer
c)instance of operator

 

46. A method which prevents child class from overriding or overloading is called as—–

a)final
b)abstract
c)polymorphism
d)inheritance

Show Answer
a)final

 

47. A class which have different functionality is called as———

a)inheritance
b)polymorphism
c)Interface
d)Abstract

Show Answer
b)polymorphism

 

48. A method used to make a copy of an object is called as——- 

a) Clone
b)Instance of
c)self
d)parent

Show Answer
a) Clone

 

49. The method with different signatures and same method name is called as———

a)Method overloading
b)Inheritance
c)Abstract
d)Final

Show Answer
a)Method overloading

 

50. The keyword used in inherit class is ———

a)implements
b)extends
c)try
d)final

Show Answer
b)extends

 

51. PHP does not support ———— inheritance

a)Multilevel
b)Single
c)Multiple
d)Hierarchical

Show Answer
c)Multiple

 

52. Static methods can be called using———

a)object
b)class
c)keywords
d)methods

Show Answer
b)class

 

53. A method which cannot be inherited is called as——–

a)final
b)abstract
c)implements
d)interface

Show Answer
a)final

 

54. Default visibility of class constants is ———

a)public
b)private
c)protected
d)Default access

Show Answer
a)public

 

55. )When an object is cloned php will perform ——–copy of all subject properties

a)shallow
b)deep
c)Low
d)High

Show Answer
a)shallow

 

56. PHP was written in _____ programming

A. C
B. C++
C. Java
D. Python

Show Answer
A. C

 

57. PHP originally stood for _____________

A. Hypertext Preprocessor
B. Personal Home Page
C. Page Hyperttext Preprocessor
D. None of the above

Show Answer
B. Personal Home Page

 

58. PHP has an extensions

A. .php
B. .php3
C. .phtml
D. All of the above

Show Answer
D. All of the above

 

59. Is PHP platform-independent

A. True
B. False

Show Answer
A. True

Leave a Comment