PHP Language | 30 Minute‐Test 2


Instruction

  • Total number of questions : 30.
  • Time alloted : 30 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which version of PHP introduced Try/catch Exception?

A.
PHP 4
B.
PHP 5
C.
PHP 5.3
D.
PHP 6

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Version 5 added support for Exception Handling.

2.

What will be the output of the following PHP code?

    <?php

    $score = 1234;

    $scoreboard = (array) $score;

    echo $scoreboard[0];

    ?>

A.
1
B.
Error
C.
1234
D.
2

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The (array) is a cast operator which is used for converting values from other data types to array.

3.

What will be the output of the following PHP code?

    <?php

    $team = "arsenal";

    switch ($team) {

    case "manu":

        echo "I love man u";

    case "arsenal":

        echo "I love arsenal";

    case "manc":

        echo "I love manc"; }

    ?>

A.
I love arsenal
B.
Error
C.
I love arsenalI love manc
D.
I love arsenalI love mancI love manu

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.

4.

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)

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

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.

5.

Which one of the following functions can be used to compress a string?

A.
zip_compress()
B.
zip()
C.
compress()
D.
gzcompress()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

We will be able to achieve almost 50% size reduction using this function. The gzuncompress() function is used to uncompress the string.

6.

Which in-built function will add a value to the end of an array?

A.
array_unshift()
B.
into_array()
C.
inend_array()
D.
array_push()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

array_push adds a value to the end of an array, returning the total count of elementsin the array after the new value has been added.

7.

What will be the output of the following PHP code ?

<?php

$a = array("a" => "Jaguar", "b" => "Land Rover", "c" => "Audi", "d" => "Maseratti");

echo array_search("Audi", $a);

?>

A.
a
B.
b
C.
c
D.
d

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_search() function searches for the element and returns the key of that element.

8.

What will be the output of the following PHP code?

<?php

$a = array("A", "Cat", "Dog", "A", "Dog");

print_r(array_count_values($a));

?>

A.
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
B.
Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
C.
Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )
D.
Array ( [A] => 2 [Cat] => 1 [Dog] => 1)

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The array_count_values() function counts all the values of an array.

9.

Say in the above question you need to get the array sorted in the manner we humans would have done it i.e picture1 then picture2 etc.. Which of the following function should be used?

A.
dsort()
B.
casesort()
C.
natcasesort()
D.
naturalsort()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

10.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

11.

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

A.
exist()
B.
exist_class()
C.
class_exist()
D.
__exist()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The class_exist() function returns true or false according to whether the class exists within the currently executing script content.

12.

Which of the following is/are true for an abstract class?
i) A class is declared abstract by prefacing the definition with the word abstract.
ii) A class is declare abstract by using the keyword implements.
iii) It is a class that really isn’t supposed to ever be instantiated but instead serves as a base class.
iv) Attempting to instantiate an abstract class results in an error.

A.
Only ii)
B.
All of the mentioned
C.
ii) and iv)
D.
ii), iii) and iv)

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

13.

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

14.

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.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

15.

Which one of the following does not describe a validating filter?

A.
Are used to allow or disallow specified characters in a string
B.
Are used to validate user input
C.
Strict format rules
D.
Returns the expected type on success or FALSE on failure

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Option a) describes Sanitizing filters.

16.

What will be the output of the following PHP code?

    <?php

    $username = "jasoN";

    if (ereg("([^a-z])",$username))

        echo "Username must be all lowercase!";

    else

        echo "Username is all lowercase!";

    ?>

A.
Error
B.
Username must be all lowercase!
C.
Username is all lowercase!
D.
No Output is returned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Because the provided username is not all lowercase, ereg() will not return FALSE (instead returning the length of the matched string, which PHP will treat as TRUE), causing the message to output.

17.

What will be the output of the following PHP code?

    <?php

    $title = "O'malley wins the heavyweight championship!";

    echo ucwords($title);

    ?>

A.
O’Malley Wins The Heavyweight Championship!
B.
O’malley Wins The Heavyweight Championship!
C.
O’Malley wins the heavyweight championship!
D.
o’malley wins the heavyweight championship!

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The ucwords() function capitalizes the first letter of each word in a string. Its prototype follows: string ucwords(string str).

18.

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()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

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

19.

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

    <?php

    echo "Today is ".date("F d, Y")

    ?>

A.
Today is 22 June, 2013
B.
Today is 22-06-2013
C.
Today is 06-22-2013
D.
Today is June 22, 2013

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

F is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year.

20.

What will be the output of the following PHP code if date is 24/02/2008?

    <?php

    $date = new DateTime();

    echo $date->format('l,F,js,Y')

    ?>

A.
Sunday, February 24th 2008
B.
Sunday, 02 24 2008
C.
Sunday, 24 02 2008
D.
Sunday, 24th February 2008

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The format() method displays the date in same way as standard date function().

21.

Which variable is used to collect form data sent with both the GET and POST methods?

A.
$BOTH
B.
$_BOTH
C.
$REQUEST
D.
$_REQUEST

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

22.

Which of the following are types of PHP authentication implementation methodologies?
i) Hard-coding a login pair directly into the script
ii) File-based authentication
iii) Data-based authentication
iv) PEAR’S HTTP authentication

A.
ii) and iii)
B.
i) and iv)
C.
ii), iii) and iv)
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

23.

What is the default value of the directive max_file_limit?

A.
10 files
B.
15 files
C.
20 files
D.
25 files

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

24.

What is the default port number of HTTP’s?

A.
70
B.
80
C.
90
D.
100

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None

25.

If session.use_cookie is set to 0, this results in use of..

A.
Session
B.
Cookie
C.
URL rewriting
D.
Nothing happens

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

26.

An attacker somehow obtains an unsuspecting user’s SID and then using it to impersonate the user inorder to gain potentially sensitive information. This attack is known as..

A.
session-fixation
B.
session-fixing
C.
session-hijack
D.
session-copy

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

You can minimize this risk by regenerating the session ID on each request while maintaining the session-specified data. PHP offers a convenient function named session_regenerate_id() that will replace the existing ID with a new one.

27.

Suppose all web material is located within the directory /home/www. To prevent users from viewing and manipulating files such as /etc/password, which one of the following statements should you use?

A.
open_dir = “/home/www/”
B.
open_dir = /home/www/
C.
open_basedir = /home/www/
D.
open_basedir = “/home/www/”

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

28.

Which one of the following preg PHP function is used to do a find and replace on a string or an array?

A.
preg_replace()
B.
preg_find()
C.
preg_find_replace()
D.
preg_findre()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

29.

Which one of the following statements is used to create a table?

A.
CREATE TABLE table_name (column_name column_type);
B.
CREATE table_name (column_type column_name);
C.
CREATE table_name (column_name column_type);
D.
CREATE TABLE table_name (column_type column_name);

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

30.

Which one of the following method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE query?

A.
num_rows()
B.
affected_rows()
C.
changed_rows()
D.
new_rows()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The method num_rows() is only useful for determining the number of rows retrieved by a SELECT query. But to retrieve the number of rows affected by INSERT, UPDATE, or DELETE query, use affected_rows().

Submit your test now to view the Results and Statistics with answer explanation.