100 Top PHP Multiple Choice Questions and Answers

PHP Multiple Choice Questions :-

1) Which of the following are not considered as Boolean false?
a. FALSE
b. 0
c. “0”
d. “FALSE”
e. 1
f. NULL
Ans: d and e

2) Consider the following class:
Class Insurance
{
function clsName()
{
echo get_class($this);
}
}
8. $cl = new Insurance();
9. $cl -> clsName();
10. Insurance::clsName();
Which of the following Lines should be commented to print the class name without errors?
a. Line 8 and 9
b. Line 10
c. Line 9 and 10
d. All the three lines 8,9, and 10 should be left as it is.
Ans: d

3) Variables/functions in PHP don’t work directly with:
a. echo()
b. isset()
c. print()
d. All of the above
Ans: b

4) What is the output of the following code?
a. Array ([x]=>9 [y]=>3 [z]=>-7)
b. Array ([x]=>3 [y]=>2 [z]=>5)
c. Array ([x]=>12 [y]=>5 [z]=>-2)
d. Error
e. None of the above
Ans: c

5) Which of the following multithreaded servers allow PHP as a plug-in?
a. Netscape FastTrack
b. Microsoft’s Internet Information Server
c. O’Reilly’s WebSite Pro
d. All of the above
Ans: d

 

6) Which of the following statements is incorrect with regard to interfaces?
a. A class can implement multiple interfaces
b. An abstract class cannot implement multiple interfaces
c. An interface can extend multiple interfaces
d. Methods with the same name, arguments and sequences can exist in the different interfaces implemented by a class
Ans: d

7) Which of the following typecast is not correct?
a. real
b. double
c. decimal
d. boolean
Ans: c

8) What will be the output of the following code?
$var = 10;
function fn ()
{
$var = 20;
return $var;
}
fn ();
echo $var;
a. 10
b. 20
c. Undefined Variable
d. Syntax Error
Ans: a

9) which of the following are the valid PHP data types?
a. resource
b. null
c. boolean
d. string
e. Both a and c
f. Both b, c and d
g. All of the above
Ans: g

10) which of the following characters are taken care of by htmlspecialchars?
a. < b. >
c. single quote
d. double quote
e. &
f. All of the above
Ans: f

11) What do you infer from the following code?
a. The only first character will be recognized and a new line will be inserted.
b. Last will not be recognized and only the first two parts will come in new lines.
c. All the will work and text will be printed on respective new lines.
d. All will be printed on one line irrespective of the
Ans: d

12) which of the following is a correct declaration?
a. static $varb = array(1,’val’,3);
b. static $varb = 1+(2*90);
c. static $varb = sqrt(81);
d. static $varb = new Object;
Ans: a

13) If visibility is not defined for a method/member then it is treated as public static
a. True
b. False
Ans: b

14) what is true regarding $a + $b where both of them are arrays?
a. Duplicated keys are NOT overwritten
b. $b is appended to $a
c. The + operator is overloaded
d. This produces a syntax error
Ans: a,b

15) Which of the following is Ternary Operator?
a. &
b. =
c.
d. ?:
e. +=
f. &&
Ans: d

16) Which of the following variables are supported by ‘str_replace()’ function?
a. Integer
b. String
c. Boolean
d. Array
Ans: b,d

17) which of the following pair have non-associative equal precedence?
a. +,-
b. ==, !=
c.
d. &=, |=
Ans: b

18) Which of the following attribute is needed for file upload via the form?
a. enctype=’multipart/form-data’
b. enctype=’single part/data’
c. enctype=’file’
d. enctype=’form-data/file’
Ans: a

19) Which of the following functions output text?
a. echo()
b. print()
c. println()
d. display()
Ans: a,b

20) The inbuilt function to get the number of parameters passed is:
a. arg_num()
b. func_args_count()
c. func_num_args()
d. None of the above
Ans: c

21) Consider the following two statements:
I while (expr) statement
II while (expr): statement… end while;
Which of the following are true in the context of the given statements?
a. I is correct and II is wrong
b. I is wrong and II is correct
c. Both I & II are the wrong
d. Both I & II are correct
Ans: d

22) Multiple select/load is possible with:
a. Checkbox
b. Select
c. File
d. All of the above
Ans: b

23) Which of the following statement is not correct for PHP?
a. It is a server-side scripting language
b. A PHP file may contain text, HTML tags or scripts
c. It can run on Windows and Linux systems the only
d. It is compatible with most of the common servers used today
Ans: c

24) Which of the following printing construct/function accepts multiple parameters?
a. echo
b. print
c. printf
d. All of the above
Ans: a

25) Does PHP provide the goto keyword in the latest version?
a. Yes, b. No
Ans: b

26) We have two variable definitions:
1. 023
b. x23
Choose the correct options:
a. 1 is octal
b. 2 is hexadecimal
c. 2 is octal
d. 1 is hexadecimal
Ans: a,b

27) Which of the following is not a predefined constant?
a. TRUE
b. FALSE
c. NULL
d. _FILE_
e. CONSTANT
Ans: d

28) What will be the output of the following code?
$a = 10;
if ($a > 5 OR < 15)
echo ‘true’;
else
echo ‘false’;
a. true
b. false
c. No output
d. Parse Error
Ans: d

29) You need to check the size of a file in the PHP function.
$size = X(filename);
Which function will suitably replace ‘X’?
a. filesize
b. size
c. size of the file

Ans: a

30) Which of the following variables is not related to file uploads?
a. max_file_size
b. max_execution_time
c. post_max_size
d. max_input_time
Ans: d

PHP Objective Questions Pdf Free Download::

31) Which of the following variable names are invalid?
a. $var_1
b. $var1
c. $var-1
d. $var/1
e. $v1
Ans: c,d

32) What will be the output of the following code?
function fn (&$var)
{
$var = $var – ($var/10*5);
return $var;
}
echo fn(100);
a. 100
b. 50
c. 98
d. Error message
e. None of the above
Ans: d

33) What will be the output of the following code?
$a = 10;
echo ‘Value of a = $a’;
a. Value of a = 10
b. Value of a = $a
c. Undefined
d. Syntax Error
Ans: a

34) What will be the output of the following code?
$Rent = 250;
function Expenses($Other)
{
$Rent = 250 + $Other;
return $Rent;
}
Expenses(50);
echo $Rent;
a. 300
b. 250
c. 200
d. The program will not compile
Ans: b

35) Which of the following variable declarations within a class is invalid in PHP5?
a. private $type = ‘moderate’;
b. internal $term= 3;
c. public $amnt = ‘500’;
d. protected $name = ‘Qantas Private Limited’;
Ans: b

36) Which of the following is used to maintain the value of a variable over different pages?
a. static
b. global
c. session_register
d. None of the above
Ans: c

37) How would you store order number (34) in an ‘OrderCookie’?
a. setcookie(‘OrderCookie’,34);
b. makeCookie(‘OrderCookie’,34);
c. Cookie(‘OrderCookie’,34);
d. OrderCookie(34);
Ans: a

38) The following PHP variables are declared:
$company = ‘ABS Ltd’;
$$company = ‘,Sydney’;
Which of the following is not a correct way of printing ‘ABS Ltd, Sydney’?
a. echo ‘$company $$company’;
b. echo ‘$company ${$company}’;
c. echo ‘$company ${‘ABS Ltd’}’;
d. echo ‘$company {$$company}’;
Ans: a

39) Which of the following regular expressions can be used to check the validity of an e-mail address?
a. ^[^@ ]+@[^@ ]+.[^@ ]+$
b. ^[^@ ]+@[^@ ]+.[^@ ]+$
c. $[^@ ]+@[^@ ]+.[^@ ]+^
d. $[^@ ]+@[^@ ]+.[^@ ]+^

Ans: b

40) You wrote the following script to check the right category:
Correct category!
Incorrect category!
What will be the output of the program if the value of ‘cate’ remains 5?
a. Correct category!
b. Incorrect category!
c. Error due to the use of the invalid operator in line 6:’if ($cate==5)’
d. Error due to incorrect syntax at line 8, 10, 12 and 14
Ans: a

41) You are using sessions and session_register() to register objects. These objects are serialized automatically at the end of each PHP page and are de-serialized automatically on each of the following pages. Is this true or false?
a. True
b. False
Ans: a

42) Which of the following is not supported in PHP5?
a. Type Hinting
b. Reflection
c. Magic Methods
d. Multiple Inheritance
e. Object Cloning
Ans: d

43) What will be the output of the following code?
echo 30*5. 7;
a. 150.7
b. 1507
c. 150.7
d. you can’t concatenate integers
e. error will occur
Ans: b

44) In your PHP application, you need to open a file. You want the application to issue a warning and continue execution, in case the file is not found. The ideal function to be used is:
a. include()
b. require()
c. nowarn()
d. getFile(false)
Ans: a

45) What will be the output of the following code?
a. int(3*4)
b. int(12)
c. 3*4
d. 12
e. None of the above
Ans: b

46) You need to count the number of parameters given in the URL by a POST operation. The correct way is:
a. count($POST_VARS);
b. count($POST_VARS_PARAM);
c. count($_POST);
d. count($HTTP_POST_PARAM);
Ans: c

47) Which of the following is correct with regard to echo and print?
a. echo is a construct and print is a function
b. echo is a function and print is a construct
c. Both are functions
d. Both are constructs
Ans: d

48) Which of the following functions output text?
a. echo()
b. print()
c. println()
d. display()
Ans: a,b

49) How would you start a session?
a. session(start);
b. session();
c. session_start();
d. begin_session();
Ans: c

50) What will be the output of the following code?
$a = 10;
echo ‘Value of a = $a’;
a. Value of a = 10
b. Value of a = $a
c. Undefined
d. Syntax Error
Ans: a

51) Which of the following is not true regarding XForms?
a. PHP provides support for XForm
b. It can be used on PDF documents
c. The data is sent in XML format
d. The action and method parameters are defined in the body
Ans: d

52) You have defined three variables $to, $subject and $body to send an email. Which of the following methods would you use for sending an email?
a. mail($to,$subject,$body)
b. sendmail($to,$subject,$body)
c. mail(to,subject,body)
d. sendmail(to,subject,body)
Ans: a

53) Which of the following are useful for method overloading?
a. __call, __get, __set
b. _get,_set,_load
c. __get,__set,__load
d. __overload
Ans: a

54) Which of the following is a PHP resource?
a. Domxml document
b. Odbc link
c. File
d. All of the above
Ans: d

55) Does PHP 5 support exceptions?
a. Yes b. No
Ans: a