Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

PHP MCQ Set 1

1. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction

View Answer

Answer: c [Reason:] None.

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?
a) Abstraction
b) Polymorphism
c) Inheritance
d) Differential

View Answer

Answer: b [Reason:] None.

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

View Answer

Answer: d [Reason:] None.

4. Which one of the following property scopes is not supported by PHP?
a) friendly
b) final
c) public
d) static

View Answer

Answer: a [Reason:] PHP supports five class property scopes: public, private, protected, final and static.

5. 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 ();

View Answer

Answer: c [Reason:] None.

6. 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’;

View Answer

Answer: d [Reason:] Class constants are created like: const NAME = ‘VALUE’;

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

View Answer

Answer: c [Reason:] None.

8. 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();

View Answer

Answer: a [Reason:] None;

9. Which of the following is/are the right way to declare a method?
i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }
a) Only ii)
b) Only iv)
c) i) and ii)
d) iii) and iv)

View Answer

Answer: c [Reason:] In case of public methods, you can forgo explicitly declaring the scope and just declare the method like you would a function.

10. Which of the following method scopes is/are not supported by PHP?
i) private
ii) final
iii) static
iv) abstract
a) Only ii)
b) Only iv)
c) ii) and iv)
d) None of the mentioned

View Answer

Answer: d [Reason:] PHP supports six method scopes: public, private, final, static, protected and abstract.

PHP MCQ Set 2

1. What will be the output of the following PHP code ?

  1. <?php
  2. echo 5 * 9 / 3 + 9;
  3. ?>

a) 24
b) 3.7
c) 3.85
d) 0

View Answer

Answer: a [Reason:] Operator precedence order must be followed.

2. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 1 + ++5;
  3. echo $var1; 
  4. ?>

a) no output
b) error
c) 6
d) 7

View Answer

Answer: b [Reason:] Operator ++ can be done only on variables.

3. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 0;
  3. $var1 = ($var1 + 5)++; 
  4. echo $var1; 
  5. ?>

a) 5
b) error
c) 6
d) 7

View Answer

Answer: b [Reason:] Operator ++ can be done only on variables.

4. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 0;
  3. $var1 = $var1++ + 5; 
  4. echo $var1; 
  5. ?>

a) 5
b) error
c) 6
d) 7

View Answer

Answer: a [Reason:] Operator precedence followed.

5. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 0;
  3. $var1 = ++$var1 + 5; 
  4. echo $var1; 
  5. ?>

a) 5
b) error
c) 6
d) 7

View Answer

Answer: c [Reason:] Operator precedence followed.

6. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 0;
  3. $var1 = $var1 + 5; 
  4. echo $var1++; 
  5. ?>

a) 5
b) error
c) 6
d) 7

View Answer

Answer: a [Reason:] Operator precedence followed,incremented after display.

7. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 1;
  3. echo $var1 = ++$var1 % 2 + ++$var1; 
  4. ?>

a) 1
b) 0
c) 2
d) 3

View Answer

Answer: d [Reason:] Evaluation done from right to left.

8. What will be the output of the following PHP code ?

  1. <?php
  2.  $a = 5;$b = -7;$c =0; 
  3.  $d = ++$a && ++$b || ++$c;
  4.  print $d;print $a;
  5. ?>

a) 16
b) 06
c) 15
d) 05

View Answer

Answer: a [Reason:] 1&&0||1 is evaluated to 1 and the a is also pre incremented to 6.

9. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 3;
  3. print $var = ++$var;
  4. ?>

a) 1
b) 0
c) 2
d) 3

View Answer

Answer: a [Reason:] $var = ++$var returns 1(success).

10. What will be the output of the following PHP code ?

  1. <?php
  2. $var1 = 3;
  3. print ++$var++;
  4. ?>

a) 3
b) 4
c) 5
d) error

View Answer

Answer: d [Reason:] First preincrement is done and the result is a number,thus post increment cannot be performed on it.

PHP MCQ Set 3

1. What will be the output of the following PHP code?

  1.     <?php
  2.     echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
  3.     ?>

a) TRUE
b) FALSE
c) Valid
d) Invalid

View Answer

Answer: d [Reason:] April has 30 days and the above date is 31 therefore Invalid is returned.

2. The date() function returns ___ representation of the current date and/or time.
a) Integer
b) String
c) Boolean
d) Float

View Answer

Answer: b [Reason:] The prototype of this function is: string date(string format [, int timestamp]).

3. Which one of the following format parameter can be used to identify timezone?
a) T
b) N
c) E
d) I

View Answer

Answer: c [Reason:] When the format is E the timezone is identified and returned…example America/New_York.

4. If the format is F then which one of the following will be returned?
a) Complete text representation of month
b) Day of month, with leading zero
c) Daylight saving time
d) Day of month, without zeros

View Answer

Answer: a [Reason:] Day of month, with leading zero is represented by D; Daylight saving time by I; Day of month, without zeros by j.

5. What will be the output of the following code? If say date is 22/06/2013.

  1.     <?php
  2.     echo "Today is ".date("F d, Y")
  3.     ?>

a) Today is 22 June, 2013
b) Today is 22-06-2013
c) Today is 06-22-2013
d) Today is June 22, 2013

View Answer

Answer: d [Reason:] F is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year.

6. Which one of the following function is useful for producing a timestamp based on a given date and time.
a) time()
b) mktime()
c) mrtime()
d) mtime()

View Answer

Answer: b [Reason:] None.

7. Which function displays the web page’s most recent modification date?
a) lastmod()
b) getlastmod()
c) last_mod()
d) get_last_mod()

View Answer

Answer: b [Reason:] The getlastmod() function returns the value of the page’s Last Modified header or FALSE in the case of an error.

8. What will be the output of the following PHP code? If say date is 22/06/2013.

  1.     <?php
  2.     printf( date("t") )
  3.     ?>

a) 30
b) 22
c) JUNE
d) 2013

View Answer

Answer: a [Reason:] The t parameter is used to determine the number of days in the current month.

9. Say you want to calculate the date 45 days from the present date which one of the following statement will you use?
a) totime(“+45”)
b) totime(“+45 days”)
c) strtotime(“+45 days”)
d) strtotime(“-45 days”)

View Answer

Answer: c [Reason:] The strtotime() function and GNU date syntax is used to calculating the date x days from the present date.

10. To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?
a) $date = Date(“22 JUNE 2013”)
b) $date = new Date(“JUNE 22 2013”)
c) $date = DateTime(“22 JUNE 2013”)
d) $date = new DateTime(“22 JUNE 2013”)

View Answer

Answer: d [Reason:] The dateTime() method is class constructor. You can set the date either at the time of instantiation or later by using a variety of mutators.

PHP MCQ Set 4

1. How many error levels are available in PHP?
a) 14
b) 15
c) 16
d) 17

View Answer

Answer: c [Reason:] None.

2. What is the description of Error level E_ERROR?
a) Fatal run-time error
b) Near-fatal error
c) Compile-time error
d) Fatal Compile-time error

View Answer

Answer: a [Reason:] None.

3. Which version of PHP introduced E_STRICT Error level?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3

View Answer

Answer: b [Reason:] Description for E_STRICT is PHP version portability suggestions

4. Which character do the error_reporting directive use to represent the logical operator NOT?
a) /
b) !
c) ~
d) ^

View Answer

Answer: c [Reason:] The twidle (~) character is used to represent the logical operator NOT.

5. Say you want to report error concerned about fatal run-time, fatal compile-time error and core error which statement would you use?
a) error_reporting = E_ALL
b) error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
c) error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR
d) error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR

View Answer

Answer: d [Reason:] None.

6. Which version introduced the function error_get_last()?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3

View Answer

Answer: c [Reason:] This function returns an associative array consisting of the type, message, file, and line of the last occurring error.

7. Which of the following statements causes PHP to disregard repeated error messages that occur within the same file and on the same line?
a) ignore_repeated_errors
b) ignore_repeat_error
c) repeatedly_ignore_error
d) repeated_error_ignore

View Answer

Answer: a [Reason:] None.

8. Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?
a) define_variable()
b) define_log_variable()
c) log_variable()
d) define_syslog_variable()

View Answer

Answer: d [Reason:] If you’re running PHP version 5.2.X or older, you need to execute this function before using any of the following logging functions.

9. Which logging option’s description is, if an error occurs when writing to the syslog, send output to the system console?
a) LOG_CONS
b) LOG_NDELAY
c) LOG_ODELAY
d) LOG_PERROR

View Answer

Answer: a [Reason:] None.

10. Which function is responsible for sending a custom message to the system log?
a) systemlog()
b) syslog()
c) log_system()
d) sys_log()

View Answer

Answer: b [Reason:] None.

PHP MCQ Set 5

1. Which version of PHP was added with Exception handling?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

View Answer

Answer: b [Reason:] Exception handling was added to PHP with the version 5 release, and further enhanced with version 5.3.

2. How many methods are available for the exception class?
a) 5
b) 6
c) 7
d) 8

View Answer

Answer: c [Reason:] The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString().

3. Which version added the method getPrevious()?
a) PHP 4
b) PHP 5
c) PHP 5.1
d) PHP 5.3

View Answer

Answer: d [Reason:] None.

4. Which of the following statements invoke the exception class?
a) throws new Exception();
b) throw new Exception();
c) new Exception();
d) new throws Exception();

View Answer

Answer: b [Reason:] None.

5. Which one of the following is the right description for the method getMessage() ?
a) Returns the message if it is passed to the constructor
b) Returns the message if it is passed to the class
c) Returns the message if it is passed to the file
d) Returns the message if it is passed to the object

View Answer

Answer: a [Reason:] None.

6. You can extend the exception base class, but you cannot override any of the preceding methods because the are declared as__________
a) protected
b) final
c) static
d) private

View Answer

Answer: b [Reason:] Marking a method as final prevents it from being overridden by a subclass.

7. What does SPL stand for?
a) Standard PHP Library
b) Source PHP Library
c) Standard PHP List
d) Source PHP List

View Answer

Answer: a [Reason:] The standard PHP library(SPL) extends PHP by offering ready-made solutions to commonplace tasks such as file access, iteration of various sorts etc.

8. How many predefined exceptions does SPL provide access to?
a) 13
b) 14
c) 15
d) 16

View Answer

Answer: a [Reason:] None.

9. Which of the following is/are not an exception?
i) BadFunctionCallException
ii) BadMethodCallException
iii) LogicException
iv) DomainException
a) All of the mentioned
b) Only iv)
c) iii) and iv)
d) None of the mentioned

View Answer

Answer: d [Reason:] None.

10. Which of the following is/are an exception?
i) OutOfBoundException
ii) OutOfRangeException
iii) OverflowException
iv) UnderflowException
a) All of the mentioned
b) i) and iii)
c) i) and ii)
d) None of the mentioned

View Answer

Answer: a [Reason:] None.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com