PHP Language | 50 Minute‐Test 1


Instruction

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

1.

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.

2.

What does PHP stand for?
i) Personal Home Page
ii) Hypertext Preprocessor
iii) Pretext Hypertext Processor
iv) Preprocessor Home Page

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.

3.

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.

4.

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.

5.

Which statement will output $x on the screen?

A.
echo “\$x‿;
B.
echo “$$x‿;
C.
echo “/$x‿;
D.
echo “$x;‿;

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A backslash is used so that the dollar sign is treated as a normal string character rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as escape character.

6.

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.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

7.

If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

A.
12
B.
1
C.
Error
D.
5

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .

8.

Who is the father of PHP?

A.
Rasmus Lerdorf
B.
Willam Makepiece
C.
Drek Kolkevi
D.
List Barely

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

9.

What will be the output of the following PHP code?

<?php

    function a()

    {

        function b()

        {

            echo 'I am b';

  }

        echo 'I am a';

    }

    a();

    a();

    ?>

A.
I am b
B.
I am bI am a
C.
Error
D.
I am a Error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

This will be the output- I am a Fatal error: Cannot redeclare b()

10.

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

11.

What will be the output of the following PHP code?

<?php

    $str = "Hello World"

    echo wordwrap($str,5,"<br>\n");   

    ?>

A.
Hello World
B.
Hello
World
C.
Hell
o wo
rld
D.
World

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Explanation:The wordwrap() function wraps a string into new lines when it reaches a specific length.

12.

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.

13.

Which function will return true if a variable is an array or false if it is not?

A.
this_array()
B.
is_array()
C.
do_array()
D.
in_array()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean is_array(mixed variable).

14.

Which function returns an array consisting of associative key/value pairs?

A.
count()
B.
array_count()
C.
array_count_values()
D.
count_values()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

15.

What will be the output of the following PHP code?

<?php

    $face = array ("A", "J", "Q", "K");

    $number = array ("2","3","4", "5", "6", "7", "8", "9", "10");

    $cards = array_merge ($face, $number);

    print_r ($cards);

    ?>

A.
Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
B.
Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
C.
Error
D.
Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => A [10] => J [11] => Q [12] => K )

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The resulting array will begin with the first input array parameter, appending each subsequent array parameter in the order of appearance.

16.

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.

17.

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

   <?php

    class Example

    {

        public $name;

        function Sample()

        {

            echo "This is an example";

        }

    }

    ?>

A.
echo “This is an example‿;
B.
public $name;
C.
class Example
D.
function sample()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Yes they are nothing but variables.

18.

The class from which the child class inherits is called..
i) Child class
ii) Parent class
iii) Super class
iv) Base class

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

19.

Which magic method is used to implement overloading in PHP?

A.
__call
B.
__invoke
C.
__wakeup
D.
__unset

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

20.

Which character do the error_reporting directive use to represent the logical operator NOT?

A.
/
B.
!
C.
~
D.
^

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The twidle (~) character is used to represent the logical operator NOT.

21.

Which function is responsible for sending a custom message to the system log?

A.
systemlog()
B.
syslog()
C.
log_system()
D.
sys_log()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

22.

Which of the following statements invoke the exception class?

A.
throws new Exception();
B.
throw new Exception();
C.
new Exception();
D.
new throws Exception();

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

23.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

24.

What will be the output of the following PHP code?

<?php

    $num = "123";

    if (!filter_var($num, FILTER_VALIDATE_INT))

        echo("Integer is not valid");

    else

        echo("Integer is valid");

    ?>

A.
No output is returned
B.
Integer is not valid
C.
Integer is valid
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

filter_var() – Filters a single variable with a specified filter.

25.

What will be the output of the following PHP code?

<?php

    function convertSpace($string)

    {

        return str_replace("_", " ", $string);

    }

    $string = "Peter_is_a_great_guy!";

    echo filter_var($string, FILTER_CALLBACK, array("options"=>"convertSpace"));

    ?>

A.
Peter_is_a_great_guy!
B.
Peterisagreatguy!
C.
Peter is a great guy!
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The code above converts all “_‿ to white spaces. Call the filter_var() function with the FILTER_CALLBACK filter and an array containing our function.

26.

How many functions does PHP offer for searching strings using POSIX style regular expression?

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

ereg(), ereg_replace(), eregi(), eregi_replace(), split(), spliti(), and sql_regcase() are the functions offered.

27.

Which among the following is/are not a metacharacter?
i)\a
ii)\A
iii)\b
iv)\B

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

\A, \b and \B are metacharacters. \A: Matches only at the beginning of the string. \b: Matches a word boundary. \B: Matches anything but a word boundary.

28.

Which one of the following functions will convert a string to all uppercase?

A.
strtoupper()
B.
uppercase()
C.
str_uppercase()
D.
struppercase()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Its prototype follows string strtoupper(string str).

29.

What will be the output of the following PHP code?

   <?php

    $url = "[email protected]";

    echo ltrim(strstr($url, "@"),"@");

    ?>

A.
[email protected]
B.
nachiketh
C.
[email protected]
D.
example.com

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The strstr() function returns the remainder of a string beginning with the first occurrence of a predefined string.

30.

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.
fgetss()
D.
fgetss()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

31.

Which of the following PHP functions can be used for generating unique id’s?

A.
uniqueid()
B.
id()
C.
mdid()
D.
mdid()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Many people use the md5() function for this, even though it’s not exactly meant for this purpose. uniqueid() is the function that is to be used.

32.

What will be the output of the following PHP code?

    <?php

    echo lcfirst("welcome to India");

    ?>

A.
welcome to India
B.
welcome to india
C.
Welcome to India
D.
Welcome to india

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The lcfirst() function converts the first character of a string to lowercase.

33.

Which of the following is the right way to use the DateTime class?

A.
$date = get_Class(DateTime);
B.
$date = class DateTime;
C.
$date = new DateTime();
D.
$date = new class DateTime();

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The way you use the DateTime class is like any other class: instantiate an object, and store it in a variable.

34.

Which method enables you to calculate whether daylight saving time is in force at a specific date and time?

A.
getOffset()
B.
getTranitions()
C.
ISODate()
D.
savingTime()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

This outputs a multidimensional array listing past and future changes to the offset from UTC for a DateTimeZone object.

35.

Which one of the following statements instantiates the mysqli class?

A.
mysqli = new mysqli()
B.
$mysqli = new mysqli()
C.
$mysqli->new.mysqli()
D.
mysqli->new.mysqli()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

If you choose to interact with MySQL server using the object-oriented interface, you need to first instantiate the mysqli class via its constructor.

36.

What will be the output of the following PHP code?

<?php

class ParentClass

{

}

 

class MyClass extends ParentClass

{

}

 

$a = new MyClass;

 

var_dump($a instanceof MyClass);

var_dump($a instanceof ParentClass);

?>

A.
bool(false)
bool(false)
B.
bool(true)
bool(true)
C.
bool(false)
bool(true)
D.
bool(true)
bool(false)

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

instanceof can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class.

37.

A mutator method is also called as..

A.
Setter
B.
Accessor
C.
Getter
D.
Destructor

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

An accessor method is called getter. The common use of a mutator method is to initialise the value of member variables of a class.

38.

Which one of the following function is used to retrieve the MX records for the domain specified by hostname?

A.
getmx()
B.
retrieve_mx()
C.
retrieve_mxrr()
D.
retrieve_mxrr()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

39.

Which of the following statements is used to add an attachment to the mail?

A.
$mimemail->attachment(‘attachment.pdf’);
B.
$mimemail=>attachment(‘attachment.pdf’);
C.
$mimemail->addAttachment(‘attachment.pdf’);
D.
$mimemail=>addAttachment(‘attachment.pdf’);

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Call the Mail_Mime object’s addAttachment() method passing in the attachment name and extension.

40.

Since which version of PHP was the directive max_file_limit available.

A.
PHP 5.2.1
B.
PHP 5.2.2
C.
PHP 5.2.12
D.
PHP 5.2.21

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The max_file_limit directive sets an upper limit on the number of files which can be simultaneously uploaded.

41.

Which function is used to determine whether a file was uploaded?

A.
is_file_uploaded()
B.
is_uploaded_file()
C.
uploaded_file(“filename‿)
D.
uploaded_file(“filename‿)

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

42.

Which version of MySQL introduced the prepared statements?

A.
MySQL 4.0
B.
MySQL 4.1
C.
MySQL 4.2
D.
MySQL 4.3

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

When the query() method is looped repeatedly it comes at a cost of both overhead, because of the need to repeatedly parsing of the almost identical query for validity, and coding convenience, because of the need to repeatedly reconfigure the query using the new values for each iteration. To help resolve the issues incurred by repeatedly executed queries, MySQL introduced prepared statements.

43.

Which method rolls back the present transaction?

A.
commit()
B.
undo()
C.
back()
D.
rollback()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Its prototype follows:
class mysqli{
boolean rollback()
}

44.

Which one of the following should not be used while sending passwords or other sensitive information?

A.
GET
B.
POST
C.
REQUEST
D.
NEXT

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Because the data is visible to everyone.

45.

Which one of the following variable cannot be used inside a static method?

A.
$this
B.
$get
C.
$set
D.
$date

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

By definition, static methods are not invoked in the context of an object. For this reason, static methods and properties are often referred to as class variables and properties.

46.

How many of the following can be contained in constants?
i) boolean
ii) integer
iii) float
iv) string

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All scalar data i.e boolean, integer, float and string can be contained in constants.

47.

Which version of PHP introduced the concept called late static binding?

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

48.

Which one of the following is the correct way of declaring a namespace?

A.
namespace my;
B.
namespace my();
C.
my namespace;
D.
namespace(my);

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The namespace declaration must be the first statement in its file.

49.

Which one of the following statements is true for require() and require_once()?

A.
They are functions.
B.
They are statements.
C.
They’ll not work if the () is not present.
D.
They can not be used to require files.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

require() and require_once() are actually statements, not functions. This means that you can omit the brackets when using them.

50.

Polymorphism is also know as…

A.
switch
B.
overact
C.
encapsulation
D.
class switching

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Polymorphism is the maintenance of multiple implementations behind a common interface.


Feedback:

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