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. Which method scope prevents a method from being overridden by a subclass?
a) Abstract
b) Protected
c) Final
d) Static

View Answer

Answer: c [Reason:] None.

2. 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)

View Answer

Answer: b [Reason:] None.

3. PHP recognizes constructors by the name_________
a) classname()
b) _construct()
c) function _construct()
d) function __construct()

View Answer

Answer: d [Reason:] A double underscore followed by the construct keyword. Its syntax is function __construct ([ argument1, argument2,…..]) { Class Initialization code }.

4. Which version of PHP introduced the instanceof keyword?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

View Answer

Answer: b [Reason:] Using instanceof keyword we can determine whether an object is an instance of a class. $manager = new Employee() … if ($manager instanceof Employee) echo “True”;

5. Which one of the following functions is used to determine whether a class exists?
a) exist()
b) exist_class()
c) class_exist()
d) __exist()

View Answer

Answer: c [Reason:] The class_exist() function returns true or false according to whether the class exists within the currently executing script content.

6. Which one of the following functions is used to determine object type?
a) obj_type()
b) type()
c) is_a()
d) is_obj()

View Answer

Answer: c [Reason:] The is_a() function returns true if object belongs to a class type or if it belongs to a class that is a child of that class. Or else false is returned.

7. Which one of the following keyword is used to inherit our subclass into a superclass?
a) extends
b) implements
c) inherit
d) include

View Answer

Answer: a [Reason:] None.

8. In the PHP code given below, what is/are the properties?

  1.     <?php
  2.     class Example 
  3.     {
  4.         public $name;
  5.         function Sample()
  6.         {
  7.             echo "This is an example";
  8.         }
  9.     } 
  10.     ?>

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

View Answer

Answer: b [Reason:] Yes they are nothing but variables.

9. Which keyword is used to refer to properties or methods within the class itself?
a) private
b) public
c) protected
d) $this

View Answer

Answer: d [Reason:] None.

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

View Answer

Answer: c [Reason:] None.

PHP MCQ Set 2

1. The filesize() function returns the file size in ___________
a) bits
b) bytes
c) kilobytes
d) gigabytes

View Answer

Answer: b [Reason:] None.

2. Which one of the following PHP function is used to determine a file’s last access time?
a) fileltime()
b) filectime()
c) fileatime()
d) filetime()

View Answer

Answer: c [Reason:] The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.

3. Which one of the following function is capable of reading a file into an array?
a) file()
b) arrfile()
c) arr_file()
d) file_arr()

View Answer

Answer: a [Reason:] None.

4. Which one of the following function is capable of reading a file into a string variable?
a) file_contents()
b) file_get_contents()
c) file_content()
d) file_get_content()

View Answer

Answer: b [Reason:] None.

5. Which one of the following function is capable of reading a specific number of characters form a file?
a) fgets()
b) fget()
c) fileget()
d) filegets()

View Answer

Answer: a [Reason:] Its prototype is string fgets(resource handle [, int length]). If the optional length parameter is omitted, 1024 character is assumed.

6. Which one of the following function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?
a) fgetsh()
b) fgetsp()
c) fgetsa()
d) fgetss()

View Answer

Answer: d [Reason:] None.

7. Which one of the following function outputs the contents of a string variable to the specified resource?
a) filewrite()
b) fwrite()
c) filewrites()
d) fwrites()

View Answer

Answer: b [Reason:] None.

8. Which function sets the file filename’s last-modified and last-accessed times?
a) sets()
b) set()
c) touch()
d) touched()

View Answer

Answer: c [Reason:] Its prototype is int touch(string filename [, int time [, int atime]]). It returns TRUE on success or FALSE on error.

9. Which function is useful when you want to output the executed command’s result?
a) out_cmm()
b) out_system()
c) cmm()
d) system()

View Answer

Answer: d [Reason:] None.

10. Which one of the following function reads a directory into an Array?
a) scandir()
b) readdir()
c) scandirectory()
d) readdirectory()

View Answer

Answer: a [Reason:] It returns an array consisting of files and directories found in directory or returns FALSE on error.

PHP MCQ Set 3

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

  1.     <?php
  2.     $a = 5;
  3.     $b = 5;
  4.     echo ($a === $b);
  5.     ?>

a) 5 === 5
b) Error
c) 1
d) False

View Answer

Answer: c [Reason:] === operator returns 1 if $a and $b are equivalent and $a and $b have the same type.

2. Which of the below symbols is a newline character?
a) r
b) n
c) /n
d) /r

View Answer

Answer: b [Reason:] PHP treats n as newline character.

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

  1.     <?php
  2.     $num = 10;
  3.     echo 'What is her age? n She is $num years old';
  4.     ?>

a) What is her age? n She is $num years old
b) What is her age?
She is $num years old
c) What is her age? She is 10 years old
d) What is her age?
She is 10 years old

View Answer

Answer: a [Reason:] When a string is enclosed within single quotes both variables and escape sequences will not be interpreted when the string is parsed.

4. Which of the conditional statements is/are supported by PHP?
i) if statements
ii) if-else statements
iii) if-elseif statements
iv) switch statements
a) Only i)
b) i), ii) and iv)
c) ii), iii) and iv)
d) All of the mentioned.

View Answer

Answer: d [Reason:] None.

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

  1.     <?php
  2.     $team = "arsenal";
  3.     switch ($team) {
  4.     case "manu":
  5.         echo "I love man u";
  6.     case "arsenal":
  7.         echo "I love arsenal";
  8.     case "manc":
  9.         echo "I love manc"; }
  10.     ?>

a) I love arsenal
b) Error
c) I love arsenalI love manc
d) I love arsenalI love mancI love manu

View Answer

Answer: c [Reason:] If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.

6. Which of the looping statements is/are supported by PHP?
i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop
a) i) and ii)
b) i), ii) and iii)
c) All of the mentioned
d) None of the mentioned

View Answer

Answer: c [Reason:] None.

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

  1.     <?php
  2.     $user = array("Ashley", "Bale", "Shrek", "Blank");
  3.     for ($x=0; $x < count($user); $x++)	{
  4.         if ($user[$x] == "Shrek") continue;
  5.             printf ($user[$x]); 
  6.     }
  7.     ?>

a) AshleyBale
b) AshleyBaleBlank
c) ShrekBlank
d) Shrek

View Answer

Answer: b [Reason:] The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.

8. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
a) 12
b) 1
c) Error
d) 5

View Answer

Answer: d [Reason:] ?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .

9. What is the value of $a and $b after the function call?

  1.     <?php
  2.     function doSomething( &$arg ) {
  3.         $return = $arg;
  4.         $arg += 1;
  5.         return $return;	
  6.     }
  7.     $a = 3;
  8.     $b = doSomething( $a );
  9.     ?>

a) a is 3 and b is 4
b) a is 4 and b is 3
c) Both are 3
d) Both are 4

View Answer

Answer: b [Reason:] $a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.

10. Who is the father of PHP?
a) Rasmus Lerdorf
b) Willam Makepiece
c) Drek Kolkevi
d) List Barely

View Answer

Answer: a [Reason:] None.

PHP MCQ Set 4

1. Which one of the following is the right way of defining a function in PHP?
a) function { function body }
b) data type functionName(parameters) { function body }
c) functionName(parameters) { function body }
d) function fumctionName(parameters) { function body }

View Answer

Answer: d [Reason:] None.

2. Type Hinting was introduced in which version of PHP?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

View Answer

Answer: b [Reason:] Type hinting gives you the ability to force parameters to be objects of certain class or to be arrays. PHP 5 introduced this feature.

3. What will happen in this function call?

  1.     <?php
  2.     function calc($price, $tax)	
  3.     {
  4.         $total = $price + $tax;
  5.     }
  6.     $pricetag = 15;
  7.     $taxtag = 3;
  8.     calc($pricetag, $taxtag);	
  9.     ?>

a) Call By Value
b) Call By Reference
c) Default Argument Value
d) Type Hinting

View Answer

Answer: a [Reason:] When you pass an argument in the above manner or say we pass 15 and 3 directly, it is called passing by value or call by value.

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

  1.     <?php
  2.     function calc($price, $tax="")
  3.     {
  4.         $total = $price + ($price * $tax);
  5.         echo "$total"; 
  6.     }
  7.     calc(42);	
  8.     ?>

a) Error
b) 0
c) 42
d) 84

View Answer

Answer: c [Reason:] You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.

5. Which of the following are valid function names?
i) function()
ii) €()
iii) .function()
iv) $function()
a) Only ii)
b) None of the mentioned.
c) All of the mentioned.
d) iii) and iv)

View Answer

Answer: a [Reason:] Except a) others are invalid names. According to the specified regular expression ([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*), a function name like this one is valid.

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

  1.     <?php
  2.     function a()
  3.     {
  4.         function b()
  5.         {
  6.             echo 'I am b';
  7.  	}
  8.         echo 'I am a';
  9.     }
  10.     a();
  11.     a();
  12.     ?>

a) I am b
b) I am bI am a
c) Error
d) I am a Error

View Answer

Answer: d [Reason:] This will be the output- I am a Fatal error: Cannot redeclare b()

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

  1.     <?php
  2.     function a()  
  3.     {
  4.         function b()
  5.         {
  6.             echo 'I am b';
  7.  	}
  8.         echo 'I am a';
  9.     }
  10.     b();
  11.     a();
  12.     ?>

a) I am b
b) I am bI am a
c) Error
d) I am a Error

View Answer

Answer: c [Reason:] This will be the output- Fatal error: Call to undefined function b(). You cannot call a function which is inside a function without calling the outside function.

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

  1.     <?php
  2.     $op2 = "blabla";
  3.     function foo($op1)
  4.     {
  5.         echo $op1;
  6.         echo $op2;
  7.     }
  8.     foo("hello");
  9.     ?>

a) helloblabla
b) Error
c) hello
d) helloblablablabla

View Answer

Answer: c [Reason:] If u want to put some variables in function that was not passed by it, you must use “global”. Inside the function type global $op2.

9. A function in PHP which starts with __ (double underscore) is know as..
a) Magic Function
b) Inbuilt Function
c) Default Function
d) User Defined Function

View Answer

Answer: a [Reason:] PHP functions that start with a double underscore – a “__” – are called magic functions in PHP. They are functions that are always defined inside classes, and are not stand-alone functions.

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

  1.     <?php
  2.     function foo($msg)
  3.     {
  4.         echo "$msg";
  5.     }
  6.     $var1 = "foo";
  7.     $var1("will this work");
  8.     ?>

a) Error
b) $msg
c) 0
d) Will this work

View Answer

Answer: d [Reason:] It is possible to call a function using a variable which stores the function name.

PHP MCQ Set 5

1. Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET

View Answer

Answer: b [Reason:] None.

2. The attack which involves the insertion of malicious code into a page frequented by other users is known as..
a) basic sql injection
b) advanced sql injection
c) cross-site scripting
d) scripting

View Answer

Answer: c [Reason:] None.

3. When you use the $_GET variable to collect data, the data is visible to..
a) none
b) only you
c) everyone
d) selected few

View Answer

Answer: c [Reason:] None.

4. When you use the $_POST variable to collect data, the data is visible to..
a) none
b) only you
c) everyone
d) selected few

View Answer

Answer: b [Reason:] The POST method, data is invisible to others.

5. Which variable is used to collect form data sent with both the GET and POST methods?
a) $BOTH
b) $_BOTH
c) $REQUEST
d) $_REQUEST

View Answer

Answer: d [Reason:] None.

6. Which one of the following should not be used while sending passwords or other sensitive information?
a) GET
b) POST
c) REQUEST
d) NEXT

View Answer

Answer: a [Reason:] Because the data is visible to everyone.

7. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()

View Answer

Answer: b [Reason:] None.

8. What will be the value of the variable $input in the following PHP code?

  1.     <?php
  2.     $input = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";
  3.     $input = strip_tags($input,"<i></i>");
  4.     ?>

a) Swapna Lawrence you are really pretty!
b) Swapna <td>Lawrence</td> you are really<i>pretty</i>!
c) Swapna <td>Lawrence</td> you are really pretty!
d) Swapna Lawrence you are really<i>pretty</i>!

View Answer

Answer: d [Reason:] Italic tags <i></i> might be allowable, but table tags <td></td> could potentially wreak havoc on a page.

9. To validate an e-mail address, which flag is to be passed to the function filter_var()?
a) FILTER_VALIDATE_EMAIL
b) FILTER_VALIDATE_MAIL
c) VALIDATE_EMAIL
d) VALIDATE_MAIL

View Answer

Answer: a [Reason:] None.

10. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?
a) 5
b) 6
c) 7
d) 8

View Answer

Answer: c [Reason:] There are seven validation filters. They are FILTER_VALIDATE_EMAIL, FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, FILTER_VALIDATE_REGEXP, FILTER_VALIDATE_URL.

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