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
2. PHP is _______ scripting language.
A. Server-side
B. Clint-side
C. Middle-side
D. Out-side
3. PHP scripts are executed on _________
A. ISP Computer
B. Client Computer
C. Server Computer
D. It depends on PHP scripts
4. PHP Scripts starts with ________
A. <php> … </php>
B. <?php …. ?>
C. ?php … ?php
D. <p> … </p>
5. Which of the following statements prints in PHP?
A. Out
B. Write
C. Echo
D. Display
6. In PHP, each statement must be end with ______
A. . (dot)
B. ; (semicolon)
C. / (slash)
D. : (colon)
7. In PHP Language variables name starts with _____
A. ! (Exclamation)
B. & (Ampersand)
C. * (Asterisk)
D. $ (Dollar)
8. In PHP Language variables are case sensitive
A. True
B. False
C. Depends on website
D. Depends on server
9. In PHP a variable needs to be declare before assign
A. True
B. False
C. Depends on website
D. Depends on server
10. Which of the following is not the scope of Variable in PHP?
A. Local
B. Global
C. Static
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
12. Which of the following is the Concatenation Operator in PHP?
A. + (Plus)
B. . (dot)
C. & (Ampersand)
D. % (Percentage)
13. Which of the following is not PHP Loops?
A. while
B. do while
C. for
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
15. Where setcookie( ) function must appear in PHP?
A. Before tag
B. After tag
C. In tag
D. Anywhere
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.
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;
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
19. What will be the result of combining a string with another data type in PHP?
A. int
B. float
C. string
D. double
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
21. PHP is a ______ typed language.
A. User
B. Loosely
C. Server
D. System
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
23. Where session_start() function must appear in PHP?
A. Anywhere
B. With <html> tag
C. After <html> tag
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
25. Which of the following is used to add comments in PHP?
A. //
B. /* … */
C. & … &
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
27. Variables are case-sensitive in PHP?
A. True
B. False
28. Which function displays the information about PHP?
A. info()
B. sysinfo()
C. phpinfo()
D. php_info()
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
30. . How PHP files can be accessed?
A. Through Web Browser
B. Through HTML files
C. Through Web Server
D. All of Above
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 ();
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’;
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)
34. PHP recognizes constructors by the name_________
a) classname()
b) _construct()
c) function _construct()
d) function __construct()
35. Which version of PHP introduced the instanceof keyword?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
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()
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()
38. Which keyword is used to refer to properties or methods within the class itself?
a) private
b) public
c) protected
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
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);
41. Which method is used to tweak an object’s cloning behavior?
a) clone()
b) __clone()
c) _clone
d) object_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
43. + is the visibility code for?
a) Public
b) Private
c) Protected
d) Friendly
44. The keyword used to work with static properties in static method is——
a)static
b)abstract
c)self
d)final
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
46. A method which prevents child class from overriding or overloading is called as—–
a)final
b)abstract
c)polymorphism
d)inheritance
47. A class which have different functionality is called as———
a)inheritance
b)polymorphism
c)Interface
d)Abstract
48. A method used to make a copy of an object is called as——-
a) Clone
b)Instance of
c)self
d)parent
49. The method with different signatures and same method name is called as———
a)Method overloading
b)Inheritance
c)Abstract
d)Final
50. The keyword used in inherit class is ———
a)implements
b)extends
c)try
d)final
51. PHP does not support ———— inheritance
a)Multilevel
b)Single
c)Multiple
d)Hierarchical
52. Static methods can be called using———
a)object
b)class
c)keywords
d)methods
53. A method which cannot be inherited is called as——–
a)final
b)abstract
c)implements
d)interface
54. Default visibility of class constants is ———
a)public
b)private
c)protected
d)Default access
55. )When an object is cloned php will perform ——–copy of all subject properties
a)shallow
b)deep
c)Low
d)High
56. PHP was written in _____ programming
A. C
B. C++
C. Java
D. Python
57. PHP originally stood for _____________
A. Hypertext Preprocessor
B. Personal Home Page
C. Page Hyperttext Preprocessor
D. None of the above
58. PHP has an extensions
A. .php
B. .php3
C. .phtml
D. All of the above
59. Is PHP platform-independent
A. True
B. False