PHP Language | 30 Minute‐Test 8


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.

PHP files have a default file extension of..

A.
.html
B.
.xml
C.
.php
D.
.ph

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

2.

What will be the output of the following code?

    <?php

    $foo = 'Bob';

    $bar = &$foo;

    $bar = "My name is $bar";

    echo $bar;

    echo $foo;

    ?>

 

A.
Error
B.
My name is BobBob
C.
My name is BobMy name is Bob
D.
My name is Bob Bob

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The $bar = &$foo; line will reference $foo via $bar.

3.

Which of the below symbols is a newline character?

A.
\r
B.
\n
C.
/n
D.
/r

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

PHP treats \n as newline character.

4.

Type Hinting was introduced in which version of PHP?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Type hinting gives you the ability to force parameters to be objects of certain class or to be arrays. PHP 5 introduced this feature.

5.

Which one of the following PHP functions can be used to find files?

A.
glob()
B.
file()
C.
fold()
D.
get_file()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Here is an example-
// get all php files AND txt files
$files = glob(‘*.{php,txt}’, GLOB_BRACE);
print_r($files);
/* output looks like:
Array
(
[0] => phptest.php
[1] => pi.php
[2] => post_output.php
.
.
.
)

6.

Which of the following are correct ways of creating an array?
i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);

A.
iii) and iv)
B.
ii) and iii)
C.
Only i)
D.
ii), iii) and iv)

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.

7.

What will be the output of the following PHP code ?

<?php

$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");

$result = array_flip($a1);

print_r($result);

?>

A.
Array ( [red] => red [green] => green [blue] => blue [yellow] => yellow )
B.
Array ( [a] => a [b] => b [c] => c [d] => d )
C.
Array ( [red] => a [green] => b [blue] => c [yellow] => d )
D.
Array ( [a] => red [b] => green [c] => blue [d] => yellow )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_flip() function flips/exchanges all keys with their associated values in an array.

8.

What will be the output of the following PHP code?

<?php

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

print_r(array_change_key_case($age, CASE_UPPER));

?>

A.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
B.
Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
C.
Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
D.
Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The array_change_key_case() function changes all keys in an array to lowercase or uppercase.

9.

Which of the functions is used to sort an array in descending order?

A.
sort()
B.
asort()
C.
rsort()
D.
dsort()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

sort() function is used to sort in ascending order where as rsort() meaning reverse sort is used for sorting in descending order.

10.

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

11.

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)

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

12.

Which version of PHP introduced the advanced concepts of OOP?

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

13.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

14.

How many methods are available for the exception class?

A.
5
B.
6
C.
7
D.
8

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString()

15.

How many types of filtering are present in PHP?

A.
3
B.
2
C.
4
D.
None

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

There are two main types of filtering: validation and sanitization.

16.

Which one of the following regular expression matches any string containing zero or one p?

A.
p+
B.
p*
C.
P?
D.
p#

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

17.

What will be the output of the following PHP code?

    <?php

    $foods = array("pasta", "steak", "fish", "potatoes");

    $food = preg_grep("/^s/", $foods);

    print_r($food);

    ?>

A.
Array ( [0] => pasta [1] => steak [2] => fish [3] => potatoes )
B.
Array ( [3] => potatoes )
C.
Array ( [1] => steak )
D.
Array ( [0] => potatoes )

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

This function is used to search an array for foods beginning with s.

18.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.

19.

The date() function returns ___ representation of the current date and/or time.

A.
Integer
B.
String
C.
Boolean
D.
Float

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

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

20.

How many constants does the DateTime class have?

A.
8
B.
9
C.
10
D.
11

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The DateTime class has 11 constants, no static properties or methods.

21.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

22.

Which of the following variables does PHP use to authenticate a user?
i) $_SERVER[‘PHP_AUTH_USER’]
ii) $_SERVER[‘PHP_AUTH_USERS’]
iii) $_SERVER[‘PHP_AUTH_PU’]
iv) $_SERVER[‘PHP_AUTH_PW’]

A.
i) and ii)
B.
ii) and iv)
C.
i) and iv)
D.
ii) and iii)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

$_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’] store the username and password values, respectively.

23.

Which of the following directive determines the maximum amount of time that a PHP script will spend attempting to parse input before registering a fatal error?

A.
max_take_time
B.
max_intake_time
C.
max_input_time
D.
max_parse_time

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

This is relevant because particularly large files can take some time to upload, eclipsing the time set by this directive.

24.

Which one of the following function checks for the existence of DNS records?

A.
checkdns()
B.
checkdnsr()
C.
checkdnsrr()
D.
checkdnsa()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

DNS records are checked based on the supplied host value and optional DNS resource record type, returning TRUE if any records are located and FALSE otherwise.

25.

How many ways can a session data be stored?

A.
3
B.
4
C.
5
D.
6

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or through user defined functions(user).

26.

What will the function session_id() return is no parameter is passed?

A.
Current Session Identification Number
B.
Previous Session Identification Number
C.
Last Session Identification Number
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

26.

Which one of the following statements should be used to disable the use of two classes administrator and janitor?

A.
disable_classes = “administrator, janitor”
B.
disable_classes = class administrator, class janitor
C.
disable_classes = class “administrator”, class “janitor”
D.
disable_class = class “administrator”, class “janitor”

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

There may be classes inside the libraries that you’d rather not make available. You can prevent the use of these classes with the disable_classes directive.

28.

What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with $num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?

A.
Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)
B.
Array([2]=>two [3]=>three [4]=>four)
C.
Array([1]=> 1)
D.
Array([0]=>0 [5]=>5)

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

When we include PREG_GREP_INVERT, this will invert our data, so instead of outputting numbers it will output our non-numeric values.

29.

The updated MySQL extension released with PHP 5 is typically referred to as..

A.
MySQL
B.
mysql
C.
mysqli
D.
mysqly

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The updated MySQL extension with PHP 5 is known as MySQL and typically referred to as mysqli.

30.

Which one of the following methods is responsible for sending the query to the database?

A.
query()
B.
send_query()
C.
sendquery()
D.
query_send()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Its prototype looks like-
class mysqli{
mixed query(string query [, int resultmode])
}

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