1. What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.

Answers:

  1. Use mysql_query() and variables: for example: $input = $_POST[‘user_input’]; mysql_query(“INSERT INTO table (column) VALUES (‘” . $input . “‘)”);
  2. Use PDO prepared statements and parameterized queries: for example: $input= $_POST[“user-input”] $stmt = $pdo->prepare(‘INSERT INTO table (column) VALUES (“:input”); $stmt->execute(array(‘:input’ => $input));
  3. Use mysql_query() and string escaped variables: for example: $input= $_POST[“user-input”] $input_safe = mysql_real_escape_string($input); mysql_query(“INSERT INTO table (column) VALUES (‘” . $input. “‘)”);
  4. Use mysql_query() and variables with a blacklisting check: for example: $blacklist = array(“DROP”,”INSERT”,”DELETE”); $input= $_POST[“user-input”] if (!$array_search($blacklist))) mysql_query(“INSERT INTO table (column) VALUES (‘” . $input. “‘)”);

2. Which of the following methods should be used for sending an email using the variables $to, $subject, and $body?

Answers:

  1. mail($to,$subject,$body)
  2. sendmail($to,$subject,$body)
  3. mail(to,subject,body)
  4. sendmail(to,subject,body)

3. Which of the following is used to maintain the value of a variable over different pages?

Answers:

  1. static
  2. global
  3. session_register()
  4. None of these

4. Which of the following will check if a function exists?

Answers:

  1. function_exists()
  2. has_function()
  3. $a = “function to check”; if ($a ()) // then function exists
  4. None of these

5. Which of the following is not a file-related function in PHP?

Answers:

  1. fclose
  2. fopen
  3. fwrite
  4. fgets
  5. fappend

6.Which of the following is true about the singleton design pattern?

Answers:

  1. A singleton pattern means that a class will only have a single method.
  2. A singleton pattern means that a class can have only one instance object.
  3. A singleton pattern means that a class has only a single member variable.
  4. Singletons cannot be implemented in PHP.

7. Which of the following characters are taken care of by htmlspecialchars?

Answers:

  1. <
  2. >
  3. single quote
  4. double quote
  5. &
  6. All of these

8. Which of the following will read an object into an array variable?

Answers:

  1. $array_variable = get_object_vars($object);
  2. $array_variable = (array)$object;
  3. $array_variable = array $object;
  4. $array_variable = get_object_vars $object;

9. Which of the following variable declarations within a class is invalid in PHP?

Answers:

  1. private $type = ‘moderate’;
  2. internal $term = 3;
  3. public $amnt = ‘500’;
  4. protected $name = ‘Quantas Private Limited’;

10. Which of the following is not a PHP magic constant?

Answers:

  1. __FUNCTION__
  2. __TIME__
  3. __FILE__
  4. __NAMESPACE__
  5. __CLASS__

11. Which of the following will print out the PHP call stack?

Answers:

  1. $e = new Exception; var_dump($e->debug());
  2. $e = new Exception; var_dump($e->getTraceAsString());
  3. $e = new Exception; var_dump($e->backtrace());
  4. $e = new Exception; var_dump($e->getString());

12. What will be the output of the following code?
<?php
var_dump (3*4);
?>

Answers:

  1. int(3*4)
  2. int(12)
  3. 3*4
  4. 12
  5. None of the above

13. Which of the following is correct about Mysqli and PDO?

Answers:

  1. Mysqli provides the procedural way to access the database while PDO provides the object oriented way.
  2. Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.
  3. MySQLi prevents SQL Injection whereas PDO does not.
  4. MySQLi is used to create prepared statements whereas PDO is not.

14. What is the correct way to send a SMTP (Simple Mail Transfer Protocol) email using PHP?

Answers:

  1. s.sendmail($EmailAddress, [$MessageBody], msg.as_string())
  2. sendmail($EmailAddress, “Subject”, $MessageBody);
  3. mail($EmailAddress, “Subject”, $MessageBody);
  4. <a href=”mailto:$EmailAddress”>$MessageBody</a>

15. Which of the following will start a session?

Answers:

  1. session(start);
  2. session();
  3. session_start();
  4. login_sesion();

16. For the following code:
<?php

function Expenses()
{
function Salary()
{
}

function Loan()
{
function Balance()
{
}
}
}

?>
Which of the following sequence will run successfully?

Answers:

  1. Expenses();Salary();Loan();Balance();
  2. Salary();Expenses();Loan();Balance();
  3. Expenses();Salary();Balance();Loan();
  4. Balance();Loan();Salary();Expenses();

17. What enctype is required for file uploads to work?

Answers:

  1. multipart/form-data
  2. multipart
  3. file
  4. application/octect-stream
  5. None of these

18. Which of the following is incorrect with respect to separating PHP code and HTML?

Answers:

  1. Use an MVC design pattern.
  2. As PHP is a scripting language, HTML and PHP cannot be separated.
  3. Use any PHP template engine e.g: smarty to keep the presentation separate from business logic.
  4. Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to views.

19. Which one of the following is not an encryption method in PHP?

Answers:

  1. crypt()
  2. md5()
  3. sha1()
  4. bcrypt()

20. What function should you use to join array elements with a glue string?

Answers:

  1. join_st
  2. implode
  3. connect
  4. make_array
  5. None of these

21. Which function can be used to delete a file?

Answers:

  1. delete()
  2. delete_file()
  3. unlink()
  4. fdelete()
  5. file_unlink()

22. What is the string concatenation operator in PHP?

Answers:

  1. +
  2. ||
  3. .
  4. |||
  5. None of these

23.Which of the following is useful for method overloading?

Answers:

  1. __call,__get,__set
  2. _get,_set,_load
  3. __get,__set,__load
  4. __overload

24. Which of the following will store order number (34) in an ‘OrderCookie’?

Answers:

  1. setcookie(“OrderCookie”,34);
  2. makeCookie(“OrderCookie”,34);
  3. Cookie(“OrderCookie”,34);
  4. OrderCookie(34);

25. What would occur if a fatal error was thrown in your PHP program?

Answers:

  1. The PHP program will stop executing at the point where the error occurred.
  2. The PHP program will show a warning message and program will continue executing.
  3. Since PHP is a scripting language so it does not have fatal error.
  4. Nothing will happen.

26. What is the correct line to use within the php.ini file, to specify that 128MB would be the maximum amount of memory that a script may use?

Answers:

  1. memory_limit = 128M
  2. limit_memory = 128M
  3. memory_limit: 128M
  4. limit_memory: 128M

27. What is the best way to change the key without changing the value of a PHP array element?

Answers:

  1. $arr[$newkey] = $oldkey; unset($arr[$oldkey]);
  2. $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]);
  3. $newkey = $arr[$oldkey]; unset($arr[$oldkey]);
  4. $arr[$newkey] = $oldkey.GetValue(); unset($arr[$oldkey]);

28. What will be the output of the following code?
<?
echo 5 * 6 / 2 + 2 * 3;
?>

Answers:

  1. 1
  2. 20
  3. 21
  4. 23
  5. 34

29. Does PHP 5 support exceptions?

Answers:

  1. Yes
  2. No

30.Which of the following is true about posting data using cURL in PHP?

Answers:

  1. Data can be posted using only the POST method.
  2. Data can be posted using only the GET method.
  3. Data can be posted using both GET and POST methods.
  4. Data cannot be posted using cURL.

31.Which of the following is the correct way to check if a session has already been started?

Answers:

  1. if (session_id()) echo ‘session started’;
  2. if ($_SESSION[«session_id»]) echo ‘session started’;
  3. if ($GLOBALS[«session_id»]) echo ‘session started’;
  4. if ($_SERVER[«session_id»]) echo ‘session started’;

32.Given the following array:
$array = array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);

Which one of the following will print 2?

Answers:

  1. echo array_search(‘green’, $array);
  2. echo array_key_exists(2, $array);
  3. echo in_array(‘green’, $array);
  4. echo array_search(‘red’,$array);

33.What is the output of the following code?
echo 0x500;
?>

Answers:

  1. 500
  2. 0x500
  3. 0500
  4. 1280
  5. 320

34.Which of the following regular expressions can be used to check the validity of an e-mail address?

Answers:

  1. ^[^@ ]+@[^@ ]+\.[^@ ]+$
  2. ^[^@ ]+@[^@ ]+.[^@ ]+$
  3. $[^@ ]+@[^@ ]+\.[^@ ]+^
  4. $[^@ ]+@[^@ ]+.[^@ ]+^

35.Which of the following is not a valid DOM method in PHP?

Answers:

  1. loadXMLFile()
  2. loadHTML()
  3. loadXML()
  4. loadHTMLFile()

36.What is the fastest way to insert an item $item into the specified position $position of the array $array?

Answers:

  1. array_splice()
  2. array_merge() and array_slice()
  3. PHP does not have any built-in function that can do this: the source array will have to be copied, and $item inserted in to the required position:
    $n = 0;
    foreach ($array as $key => $val) {
    if ($n == $position) {
    $target[] = $item;
    }
    ++$n;
    $target[$key] = $val;
    }
  4. array_insert()

37.Consider the following 2D array in PHP:
$array = array(array(141,151,161), 2, 3, array(101, 202, 303));
Which of the following will display all values in the array?

Answers:

  1. function DisplayArray($array) {
    foreach ($array as $value) {
    if (array_valid($value)) {
    DisplayArray($value);
    } else {
    echo $value. “ ”;
    }
    }
    }
    DisplayArray($array);
  2. function DisplayArray($array) {
    for ($array as $value) {
    if (valid_array($value)) {
    DisplayArray($value);
    } else {
    echo $value. “ ”;
    }
    }
    }
    DisplayArray($array);
  3. function DisplayArray($array) {
    for ($array as $value) {
    if (is_array($value)) {
    DisplayArray($value);
    } else {
    echo $value. “ ”;
    }
    }
    }
    DisplayArray($array);
  4. function DisplayArray($array) {
    foreach ($array as $value) {
    if (is_array($value)) {
    DisplayArray($value);
    } else {
    echo $value “ ”;
    }
    }
    }
    DisplayArray($array);

38. Why is it not recommended to use $_REQUEST when handling form submissions in PHP?

Answers:

  1. It’s difficult to determine whether it is a $_POST or $_GET request.
  2. $_REQUEST is deprecated
  3. $_REQUEST includes $_COOKIE by default, and parameters from $_COOKIE with the same name may be overriden with parameters from $_GET or $_POST.
  4. $_REQUEST does not handle HTTP rquests, it handles database requests.

39.How should a variable be declared in a function, if the value has to be retained over multiple calls?

Answers:

  1. local
  2. global
  3. static
  4. None of these

40.Which is the best way to automatically deploy a PHP website using git push?

Answers:

  1. . It is not possible.
  2. You should have two copies on your server. A bare copy, that you can push/pull from, to which you would push your changes to when you are done. Then you would clone this into your web directory and set up a cronjob to update git pull from your web directory every day or couple of days.
  3. Developing from scratch a custom deployment script to manage all the aspects.
  4. Copy over your git directory to your web server. On your local copy, modify your .git/config file and add your web server as a remote. On the server, replace .git/hooks/post-update with an existing script to process the rest of the workflow.
    Make the script executable.

41.With what encoding does chr () work?

Answers:

  1. ASCII
  2. UTF-8
  3. UTF-16
  4. Implementation dependent
  5. None of the above

42.Which of the following file modes is used to write into a file at the end of the existing content, and create the file if the file does not exist?

Answers:

  1. r+
  2. w+
  3. a()
  4. x

43.Without introducing a non-class member variable, which of the following can be used to keep an eye on the existing number of objects of a given class?

Answers:

  1. Adding a member variable that gets incremented in the default constructor and decremented in the destructor.
  2. This cannot be accomplished since the creation of objects is being done dynamically via «new.»
  3. Add a static member variable that gets incremented in each constructor and decremented in the destructor.
  4. Adding a local variable that gets incremented in each constructor and decremented in the destructor.

44.What is the output of the following code?

<?php
function abc()
{
return __FUNCTION__;
}
function xyz()
{
return abc();
}
echo xyz();
?>
Answers:

  1. abc
  2. __FUNCTION__
  3. xyz

45.Which of the following is the operator with the highest precedence?

Answers:

  1. +
  2. instanceof
  3. new
  4. =
  5. none of above

46.Which function is used to remove the first element of an array?

Answers:

  1. array_remove_first_element
  2. array_shift
  3. array_ltrim
  4. a[0] = nil
  5. None of these

47.Which of the following functions output text?
Note: There may be more than one right answer.

Answers:

  1. echo()
  2. print()
  3. println()
  4. display()

48. What is the best way to load a file that contains necessary functions and classes?

Answers:

  1. include($filename);
  2. require($filename);
  3. include_once($filename);
  4. require_once($filename);

49.With regard to abstract classes, which of the following statements is false?

Answers:

  1. Abstract classes are not available in PHP.
  2. A class with a single abstract method must be declared abstract.
  3. An abstract class can contain non-abstract methods.
  4. An abstract method must have a method definition and can have optional empty braces following it.

50. What is the output of the following code?
<?php
function
vec_add (&amp;$a, $b)
{
$a[‘x’] += $b[‘x’];
$a[‘y’] += $b[‘y’];
$a[‘z’] += $b[‘z’];
}
$a = array (x =&gt; 3, y =&gt; 2, z =&gt; 5);
$b = array (x =&gt; 9, y =&gt; 3, z =&gt; -7);
vec_add (&amp;$a, $b);
print_r ($a);
?>
Answers:

  1. Array
    (
    [x] => 9
    [y] => 3
    [z] => -7
    )
  2. Array
    (
    [x] => 3
    [y] => 2
    [z] => 5
    )
  3. Array
    (
    [x] => 12
    [y] => 5
    [z] => -2
    )
  4. Error
  5. None of these

51.Which of the following are not considered as Boolean false?

Answers:

  1. FALSE
  2. 0
  3. «0»
  4. «FALSE»
  5. 4
  6. -4
  7. null

52.Which of the following code snippets has the most appropriate headers to force the browser to download a CSV file?

Answers:

  1. header(«Content-type: text/csv»);
    header(«Content-Disposition: attachment; filename=file.csv»);
    header(«Pragma: no-cache»);
    header(«Expires: 0»);
  2. header(‘Content-Type: application/download’);
    header(«Content-Disposition: attachment; filename=file.csv»);
    header(«Pragma: no-cache»);
    header(«Expires: 0»);
  3. header(‘Content-Type: application/csv’);
    header(«Content-Disposition: attachment; filename=file.csv»);
    header(«Pragma: no-cache»);
    header(«Expires: 0»);
  4. header(‘Content-Type: application/octet-stream’);
    header(«Content-Disposition: attachment; filename=file.csv»);
    header(«Pragma: no-cache»);
    header(«Expires: 0»);

53. What is the output of the following code?
<?php
echo «<pre>»;
$array = array(«red»,»green»,»blue»);
$last_key = end(array_keys($array));
foreach ($array as $key => $value) {
if ($key == $last_key) {
echo «a<br>»;
} else {
echo «b<br>»;
}
}
?>
Answers:

  1. b
    a
    b
  2. b
    a
    a
  3. b
    a
    a
  4. b
    b
    b

54.With regards to the «static» keyword in PHP, which of the following statements is false?

Answers:

  1. The $this variable can be used inside any static method.
  2. Static properties may only be initialized using a literal or a constant.
  3. A property declared as static can not be accessed with an instantiated class object.
  4. A static variable or method can be accessed without requiring instantiation of the class.

55. What is «empty()»?

Answers:

  1. A function
  2. A language construct
  3. A variable
  4. A reference
  5. None of these

56.Which of the following is not a valid cURL parameter in PHP?

Answers:

  1. CURLOPT_RETURNTRANSFER
  2. CURLOPT_GET
  3. CURLOPT_POST
  4. CURLOPT_POSTFIELDS

57.What will be the output of the following code?
<?
$a = 0;
echo ~$a;
?>
Answers:

  1. -1
  2. 0
  3. 1
  4. 10
  5. Syntax error

58.When comparing two arrays, what is the difference between «==» and «===»?

Answers:

  1. «==» compares keys while «===» compares keys and values.
  2. «===» also compares the order and types of the objects.
  3. «===» compares the array references.
  4. «===» They are identical.
  5. None of these

59.Which of the the following are PHP file upload-related functions?

Answers:

  1. upload_file()
  2. is_uploaded_file()
  3. move_uploaded_file()
  4. None of these

60.Which of the following is not a valid API?

Answers:

  1. trigger_print_error()
  2. trigger_error()
  3. debug_backtrace()
  4. debug_print_backtrace()

61.What will be the output of the following code?

<?php echo 30 * 5 . 7; ?>

Answers:

  1. 150.7
  2. 1507
  3. Integers can’t be concatenated.
  4. An error will be thrown.

62.Which of these is not a valid SimpleXML Parser method?

Answers:

  1. simplexml_import_dom()
  2. simplexml_import_sax()
  3. simplexml_load_string()

63.Which of the following environment variables is used to fetch the IP address of the user in a PHP application?

Answers:

  1. $IP_ADDR
  2. $REMOTE_ADDR_USER
  3. $REMOTE_ADDR
  4. $IP_ADDR_USER

64.Consider the following class:

  1. class Insurance
  2. {
  3. function clsName()
  4. {
  5. echo get_class($this);
  6. }
  7. }
  8. $cl = new Insurance();
  9. $cl->clsName();
  10. Insurance::clsName();

Which of the following lines should be commented to print the class name without errors?

Answers:

  1. Line 8 and 9
  2. Line 10
  3. Line 9 and 10
  4. All the three lines 8,9, and 10 should be left as it is.

65.What is the correct syntax of mail() function in PHP?

Answers:

  1. mail($from,$to,$subject,$message)
  2. mail($to,$subject,$message,$headers)
  3. mail($from,$to,$subject,$message)
  4. mail($to,$from,$subject,$message)
  5. mail($to,$from,$message,$headers).

66.Given the following array:
$array = array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);
Which one of the following will print 2?
Answers:

  1. echo array_search(‘green’, $array);
  2. echo in_array(‘green’, $array);
  3. echo array_key_exists(2, $array);
  4. echo array_search(‘red’,$array);

67.Which function will suitably replace ‘X’ if the size of a file needs to be checked?
$size=X(filename);

Answers:

  1. size
  2. filesize
  3. sizeofFile
  4. getSize

68. Which of the following will not give the correct date and time in PHP?

Answers:

  1. date(“Y-m-d H:i:s”)
  2. date(“y-m-d H:i:s”)
  3. date(“f, j Y H:i:s”)
  4. date(“F, j Y H:i:s”)

69.Which of the following functions is not used in debugging?

Answers:

  1. var_dump()
  2. fprintf()
  3. print_r()
  4. var_export()

70.What is the difference between die() and exit() in PHP?

Answers:

  1. die() is an alias for exit().
  2. exit() is a function, die() is a language construct and cannot be called using variable functions.
  3. die() accepts a string as its optional parameter which is printed before the application terminates; exit() accepts an integer as its optional parameter which is passed to the operating system as the exit code.
  4. die() terminates the script immediately, exit() calls shutdown functions and object destructors first.

71.Should assert() be used to check user input?

Answers:

  1. Yes
  2. No

72.Without introducing a non-class member variable, which of the following can be used to keep an eye on the existing number of objects of a given class?

Answers:

  1. Adding a member variable that gets incremented in the default constructor and decremented in the destructor.
  2. Adding a local variable that gets incremented in each constructor and decremented in the destructor.
  3. Add a static member variable that gets incremented in each constructor and decremented in the destructor.
  4. This cannot be accomplished since the creation of objects is being done dynamically via “new.”

73.Which of the following is the right MIME to use as a Content Type for JSON data?

Answers:

  1. text/x-json
  2. text/javascript
  3. application/json
  4. application/x-javascript

74.What would be the output of the following code?
<?php
$arr = array(«foo»,
«bar»,
«baz»);
for ($i = 0; $i < count($arr); $i++) {
$item = $arr[$i];
}
echo «<pre>»;
print_r($item);
echo «</pre>»;
?>
Answers:

  1. Array ( [0] => foo [1] => bar [2] => baz )
  2. foot
  3. bar
  4. baz

75.Which of the following is the correct way to check if a session has already been started?

Answers:

  1. if ($_SERVER[“session_id”]) echo ‘session started’;
  2. if (session_id()) echo ‘session started’;
  3. if ($_SESSION[“session_id”]) echo ‘session started’;
  4. if ($GLOBALS[“session_id”]) echo ‘session started’;

76.What is the correct PHP command to use to catch any error messages within the code?

Answers:

  1. set_error(‘set_error’);
  2. set_error_handler(‘error_handler’);
  3. set_handler(‘set_handler’);
  4. set_exception(‘set_exception’);

77.What is the correct PHP command to use to catch any error messages within the code?

Answers:

  1. set_error(‘set_error’);
  2. set_error_handler(‘error_handler’);
  3. set_handler(‘set_handler’);
  4. set_exception(‘set_exception’);

78.What is wrong with the following code?

<?php
curl_setopt($ch, CURLOPT_URL, «http://www.example.com/»);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
Answers:

  1. There is nothing wrong with the code.
  2. The cURL resource $ch has not been created using the curl_init() method.
  3. The $ch variable needs to be initialized as $ch=null;.
  4. The code will cause a parse error.

79.With what encoding does chr() work?

Answers:

  1. ASCII
  2. UTF-8
  3. UTF-16
  4. Implementation dependent
  5. None of these

80.Which of the following is not related to debugging in PHP?

Answers:

  1. PDO
  2. watch
  3. breakpoints
  4. call stack

81.Which of the following is not a predefined constant?

Answers:

  1. TRUE
  2. __FILE__
  3. FALSE
  4. NULL
  5. CONSTANT

82. What will be the output of the following code?
<?php
$str=»Hello»;
$test=»lo»;
echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;
?>
Answers:

  1. Syntax error
  2. 1
  3. FALSE
  4. 0

83. With the following code, will the word Hello be printed?
<?
//?>Hello
Answers:

  1. Yes
  2. No

84.Which of the following features are supported in PHP5?
Note: There may be more than one right answer.

Answers:

  1. Multiple Inheritance
  2. Embedded Database with SQLite
  3. Exceptions and Iterators
  4. Interoperable XML Tools

85.Consider the following statements:
I : while (expr) statement
II : while (expr): statement … endwhile;

Answers:

  1. I is correct and II is wrong.
  2. I is wrong and II is correct.
  3. Both I and II are wrong.
  4. Both I and II are wrong.

86.Which of the following type cast is not correct?
<?php
$fig = 23;
$varb1 = (real) $fig;
$varb2 = (double) $fig;
$varb3 = (decimal) $fig;
$varb4 = (bool) $fig;
?>
Answers:

  1. real
  2. double
  3. decimal
  4. boolean

87.Which of the following printing construct/function accepts multiple parameters?
Note: There may be more than one right answer.

Answers:

  1. echo
  2. print
  3. printf
  4. All of these

88.Which of the following is false about cURL?

Answers:

  1. cURL can be used to send plain text data to a remote server.
  2. cURL can be used to send both text as well as files using a single request.
  3. cURL can be used to send files to a remote server.
  4. Files cannot be sent using cURL.

89.Which of the following cryptographic functions in PHP returns the longest hash value?

Answers:

  1. md5()
  2. sha1()
  3. crc32()
  4. All return the same hash value length.

90.Which of these is not a valid PHP XML API?

Answers:

  1. a.libxml_clear_errors()
  2. b.libXMLError()
  3. c.libxml_get_errors()
  4. d.libxml_use_internal_errors()

91.Which statement will return true?

Answers:

  1. a. is_numeric(«200»)
  2. b. is_numeric(«20,0»)
  3. c. is_numeric(«$200»)
  4. d. is_numeric(«.25e4»)
  5. None

92.Which of the following statements regarding PHP forms, are correct?

Answers:

  1. In PHP, the predefined $_POST variable is used to collect values in a form with method=«post»
  2. In PHP, the predefined $_GET variable is used to collect values in a form with method=«get»
  3. In PHP, the predefined $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.
  4. Information sent from a form with the POST method is invisible to others and has an 8MB limit on the amount of information to send, which cannot be changed.

93.What is the output of the following code?
<?php
$array = array(«1″,»2″,»3″,»4»);
$variable = end(array_keys($array));
echo $variable;
?>
Answers:

  1. 1
  2. 2
  3. 3
  4. 4

94.Which of the following is not a valid php.ini parameter with respect to file uploading?

Answers:

  1. upload_max_filesize
  2. allow_url_fopen
  3. upload_tmp_dir
  4. post_max_size

95.Which of the following is not a valid xdebug configuration setting?

Answers:

  1. xdebug.var_display_max_depth
  2. xdebug.var_display_max_children
  3. xdebug.var_display_max_data
  4. xdebug.trace

96. What is the output of the following code?
<?php
echo 0x500;
?>
Answers:

  1. 500
  2. 0x500
  3. 0500
  4. 1280
  5. 320

97.Which of the following statements is true about the «new» operator in PHP?

Answers:

  1. It is used to define a new variable.
  2. It creates and allocates memory for a new object
  3. It is used to call the constructor
  4. The “new” operator does not exist in PHP

98.What is the output of the following code?
<?
$a = 0;
echo ~$a;
?>
Answers:

  1. -1
  2. 0
  3. 1
  4. 10
  5. Syntax error

99.With the following code, will the word Hello be printed?
<?
//?>Hello
Answers:

  1. yes
  2. no

100.Which of the following features are supported in PHP5?
Note: There may be more than one right answer.

Answers:

  1. Multiple Inheritance
  2. Embedded Database with SQLite
  3. Exceptions and Iterators
  4. Interoperable XML Tools

101.What is the proper definition of stdClass?

Answers:

  1. stdClass is php’s generic base class, kind of like Object in Java or object in Python
  2. stdClass is a generic ’empty’ class that’s used when casting other types to objects
  3. stdClass is a C++ construct used in the std:: libraries
  4. stdClass the base class which must be used to create anonymous classes.

102. Which of the following are valid PHP data types?

Answers:

  1. resource
  2. null
  3. boolean
  4. string
  5. All of these

103.Which of the following variables are supported by ‘str_replace()’ function?

Answers:

  1. Integer
  2. String
  3. boolean
  4. Array

104.Which of the following methods is used to check if an array is associative or numeric?

Answers:

  1. is_Assoc().
  2. isAssoc().
  3. is_assoc()
  4. None of the above.

105.Which of the following statements is incorrect, with regards to inheritance in PHP?

Answers:

  1. A class can only have a single parent, i.e. it cannot extend more than one class
  2. A class can both extend another class as well as implement an interface.
  3. A class can implement more than one interface.
  4. A class can extend more than one class.

106.Which of the following is the correct way to convert a variable from a string to an integer?

Answers:

  1. $number_variable = int_val $string_variable;
  2. $number_variable = (int_val)$string_variable;
  3. $number_variable = int($string_variable);
  4. $number_variable = (int)$string_variable;

107.What is the correct way to read-in multiple values from an array?

Answers:

  1. $x,$y,$z = array(7,8,9);
  2. ($x,$y,$z) = array(7,8,9);
  3. array($x,$y,$z) = array(7,8,9);
  4. list($x,$y,$z) = array(7,8,9);

108.Which MIME type need to be used to send attachment in mail?

Answers:

  1. text/html
  2. text/plain
  3. application/mixed
  4. multipart/mixed

109. Which of the following data type can not be directly manipulated by the Client?

Answers:

  1. Cookie Data
  2. referrer
  3. User Agent
  4. Session data

110. What is the output of the following code?

Answers:

  1. <empty output>
  2. A
  3. B
  4. AB

111. Which of the following will return the complete URL of the requested PHP page?

Answers:

  1. apache_getenv(«HTTP_HOST»)
  2. $_SERVER[‘HTTP_HOST’]
  3. $_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
  4. $_SERVER[‘REQUEST_URI’];

112. Which of the following is false about foreach loop in PHP?

Answers:

  1. The foreach construct provides an easy way to iterate over arrays.
  2. foreach works only on arrays and objects.
  3. foreach loop can be used with a variable of any type.
  4. foreach does not support the ability to suppress error messages using ‘@’.

113.What is the output of the following code?
<?php
function y($v) {
echo $v;
}
$w = «y»;
$w(«z»);
$w = «x»;
?>
Answers:

  1. x
  2. y
  3. z
  4. <error>

114.Which of the following statement is correct?

Answers:

  1. Interfaces can extend more than one interface
  2. Interfaces can extend only one interface
  3. Interfaces can inherit a method from different interfaces
  4. Interfaces can re-declare inherited methods

115.Which of the following is true regarding the str_replace() function in PHP?

Answers:

  1. It requires a minimum of 2 parameters.
  2. The first argument is the string or array being searched and replaced.
  3. The second argument is the the replacement value that replaces found search values.
  4. It will replace only the first matched string.

116.Which of the following is incorrect way to take a PHP variable named $name and reassign it to a javascript variable var name?

Answers:

  1. <script>
    var name = «<?php echo $name;?>»;
    </script>
  2. <script>
    var name =<?php echo $name;?>;
    </script>
  3. <script>
    var name = <?php echo json_encode($name);?>;
    </script>
  4. <script>
    var name = «<?php echo addslashes($name);?>»;
    </script>

117.Which is true about the curl_setopt() API?

Answers:

  1. PHP does not provide such an API.
  2. It sets multiple options for a cURL transfer.
  3. It executes the curl command.
  4. It sets one option for a cURL transfer.

118.Which of the following is the best way to convert one date format into another; portable for all PHP versions?

Answers:

  1. $myDateTime = DateTime::createFromFormat(‘Y-m-d’, $dateString);
    $newDateString = $myDateTime->format(‘m/d/Y’);
  2. $old_date = date(‘l, F d y h:i:s’);
    $old_date_timestamp = strtotime($old_date);
    $new_date = date(‘Y-m-d H:i:s’, $old_date_timestamp);
  3. implode(‘-‘, array_reverse(explode(‘-‘, $date)));
  4. $old_date = date(‘y-m-d-h-i-s’);
    preg_match_all(‘/(\.+)-(\d+)-(\w+)-(\d+)-(\w+)-(\w+)/’, $old_date, $out);
    $out = $out[0];
    $time = mktime($out[4], $out[5], $out[6], $out[2], $out[3], $out[1]);
    $new_date = date(‘Y-m-d H:i:s’, $time);

119.In mail($param1, $param2, $param3, $param4); the $param2 contains:

Answers:

  1. The message
  2. The subject
  3. The header
  4. The recipient

120.Which code snippet outputs a random string?

Answers:

  1. <?php
    Function RandomString()
    {
    $characters = ’0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
    $randstring = »;
    for ($i = 0; $i < 10; $i++) { $randstring = $characters[rand(0, strlen($characters))]; } return $randstring; } RandomString(); echo $randstring; ?>
  2. function generateRandomString($length = 10) {
    $characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
    $randomString = »;
    for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) — 1)]; } return $randomString; }
  3. function generateRandomString($length = 15)
    {
    return substr(sha1(rand()), 0, 0);
    }
  4. function RandomString($length) {
    $keys = array_merge(range(0,9), range(‘a’, ‘z’));
    for($i=0; $i < $length; $i++) { $key = $keys[array_rand($keys)]; } return $key; }

121.Which is the best approach to parse HTML and extract structured information from it?

Answers:

  1. Use an existing LibXML based library like DOM or phpQuery.
  2. String searching and extraction.
  3. Use an XML parser (as simpleXML) and XPath queries if available.
  4. Use specific regular expressions.

122.Which of the following is incorrect about empty()?

Answers:

  1. empty() checks if a variable is empty.
  2. empty() can check expressions.
  3. empty() can only check variables.
  4. empty() returns false if a variable exists and has a non-empty value.

123.Which of the following is incorrect about the Common Gateway Interface (CGI)?

Answers:

  1. CGI is a standard method for web server software to delegate the generation of web content to executable files.
  2. CGI is the part of the Web server that can communicate with other programs running on the server.
  3. A CGI program is any program designed to accept and return data that conforms to the CGI specification. The program can only be written in PHP.
  4. A CGI program is any program designed to accept and return data that conforms to the CGI specification. The program could be written in any programming language C, Perl, Java etc.

124.What will be the output of the following code?
<?php
$x = 10;
if ($x == 10):
?>
<p>Hi!</p>
<?php else:?>
<p>Bye!</p>
<?php endif; ?>
Answers:

  1. Hi!
  2. Bye!
  3. The code will throw an error, as there is no curly brace after the if statement, and it has a misplaced colon(:).
  4. The code will throw an error, as there is no curly brace after the else statement, and it has a misplaced colon(:).

125.What is the output of the following cod
<?php
echo «<pre>»;
$array1 = array(
«1»=>»a»,
«2»=>»b»,
«3»=>»c»
);
$array = array_flip($array1);
print_r($array);
echo «</pre>»;
?>

Answers:

  1. Array
    (
    [1] => a
    [2] => b
    [3] => c
    )
  2. Array
    (
    [a] => 1
    [b] => 2
    [c] => 3
    )
  3. Array
    (
    [0] => c
    [1] => b
    [2] => a
    )
  4. Array
    (
    [0] => 1
    [1] => 2
    [2] => 3
    )

126.Given a statement
«While sending a long string in PHP mail() a special character (!) is automatically inserted»
Which one of the following is true with respect to above statement?

Answers:

  1. There is a limit to the number of characters in a line of an email.
  2. The statement given is false and this never happens.
  3. This in a well known problem of PHP’s mail() function and can not be solved.
  4. None of the above.

127.What will be the output of the following code?
<?php
$numbers=array();
$numbers[1] = 1;
$numbers[2] = 2;
$numbers[3] = 3;
$numbers[4] = 4;
$key= array_search(3,$numbers);
unset($numbers[$key]);
print_r($numbers);
?>

Answers:

  1. Array ( [1] => 1 [2] => 2 [3] => 4 )
  2. Array ( [1] => 1 [2] => 2 [4] => 4 )
  3. Array ( [0] => 1 [1] => 2 [2] => 4 )
  4. Array ( [0] => 1 [2] => 2 [3] => 4 )

128.Which of the following options may be a reason for the error — «Call to undefined function curl_init()»?

Answers:

  1. cURL is not enabled.
  2. curl_init() is not a valid API.
  3. cURL only works on Linux.
  4. All of these.

129.What is the use of memory_get_peak_usage()?

Answers:

  1. Returns the available memory on RAM.
  2. Returns the peak of memory allocated by PHP.
  3. Returns the peak of memory allocated by OS.
  4. No such function exist.

130.What is true about ini_set(‘memory_limit’,’-1′)?

Answers:

  1. The script will have no memory limit.
  2. The script will have 1 MB memory
  3. The script will have 1 KB memory
  4. parse error.

131.What is the correct way to read the result of a variable dump into a string?

Answers:

  1. $string = explode($variable);
  2. $string = print_r($variable);
  3. $string = serialize($variable);
  4. $string = var_dump($variable);

132.Which of the following is a possible way to prevent Session Hijacking?

Answers:

  1. Use enough random input for generating the session ID
  2. Use HTTPS to protect the session ID during transmission
  3. Set the cookie with the HttpOnly and Secure attributes to forbid access via JavaScript
  4. Regenerating the session ID after successful login

133. What is the use of the CDATA section in XML?

Answers:

  1. CDATA is used to store the content of an XML node.
  2. CDATA is used to skip invalid characters.
  3. XML does not have any CDATA section.
  4. CDATA is used when PHP is used to update the content of an XML file.

134. Which of the following is not a valid PHP debugger?

Answers:

  1. PHPTracer
  2. Zend Debugger
  3. APD
  4. Xdebug

135. Why simple mail() function should not be used to send bulk mails in PHP?

Answers:

  1. There is a limit to number of mails can be send using mail() function.
  2. mail() function can not be used in a loop.
  3. mail() function opens and closes an SMTP socket for each email, which is not very efficient.
  4. There is no problem in using mail() function to send bulk mails.

136. Given the following code:-
Class Registry {
private $vars = array();
public function __set($key, $val) {
$this->vars($key) = $val;
}
public function __get($key) {
return $this->vars($key);
}
}
$registry = new Registry;
$registry->foo = “foo”;
echo $registry->foo;

What will be the output of the following code?

Answers:

  1. fatal error : undefined property foo
  2. foo
  3. nothing
  4. can not access the property foo outside the class Registry

137. Which method is used to sort multidimensional arrays in PHP?

Answers:

  1. krsort
  2. rsort
  3. array_multisort
  4. usort

138. Suppose after successful login following values are stored in session as per the given code:-
session_start();

$_SESSION[‘logged’] = 1;
$_SESSION[‘id’] = $id;
$_SESSION[‘name’] = $contact_name;
$_SESSION[’email’] = $email;

Now how will you remove the email value from the session?

Answers:

  1. unset($_SESSION)
  2. unset($_SESSION[’email’])
  3. session_destory($_SESSION)
  4. All of the above.

139. Some databases support the LIMIT clause. It is a method to ensure that:

Answers:

  1. Only certain rows are deleted in DELETE queries.
  2. Only a defined subset of rows are read in SELECT queries.
  3. Only certain users can access the database.

140.Which of the following is false with respect to Bridge pattern in PHP?

Answers:

  1. Bridge is designed up-front to let the abstraction and the implementation vary independently
  2. Decouple an abstraction from its implementation so that the two can vary independently.
  3. Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.
  4. Use bridge when you do not want to share an implementation among multiple objects.

141. You can extend the exception base class, but you can not override any of the preceding methods because they are declared as:

Answers:

  1. protected
  2. final
  3. Pstatic.
  4. private

142. Which one of the following is not a valid argument to error_reporting?

Answers:

  1. E_STRICT
  2. E_ALL
  3. E_STRICT
  4. E_PARSE_ERROR

143. Which one of the following is not a valid argument to error_reporting?

Answers:

  1. var_dump(isset($var))
  2. var_dump(is_null($var))
  3. var_dump(empty($var))
  4. var_dump(defined($var))

144. What will be the output of the following code?
<?php
class FormBuilder
{
private $elements = array();
public function label($text) {
$this->elements[] = «<label>$text</label>»;
return $this;
}
public function input($type, $name, $value = ») {
$this->elements[] = «<input type=\»$type\» name=\»$name\» value=\»$value\» />»;
return $this;
}
public function textarea($name, $value = ») {
$this->elements[] = «<textarea name=\»$name\»>$value</textarea>»;
return $this;
}
public function __toString() {
return join(«\n», $this->elements);
}
}
$b = new FormBuilder();
echo $b->label(‘Name’)->input(‘text’, ‘name’)->textarea(‘message’, ‘My message’);

Answers:

  1. <label>Name</label>
  2. <label>Name</label>
    <input type=»text» name=»name»/>
    <textarea name=»message»>My message</textarea>
  3. <label>Name/label>
    <input type=»text» name=»name» value=»» />
    <textarea name=»message»>My message</textarea>
  4. Fatar error on the last line since calling of class methods can not be nested.

145. How to get information from a form that is submitted using the “get” method?

Answers:

  1. Request.Form;
  2. $_GET()
  3. Request.Get;
  4. $_GET[];

146. Which of the following is the correct way to create an array in PHP?

Answers:

  1. $animals = array (Cat, Dog, Horse);
  2. $animals = array (“Cat”, “Dog”, “Horse”);
  3. $animals = array [Cat, Dog, Horse];
  4. $animals = “Cat”, “Dog”, “Horse”;

147. Which of the following magic constant of PHP returns function name?

Answers:

  1. __LINE__
  2. __FILE__
  3. __FUNCTION__
  4. __CLASS__

148. By which delimiters are PHP scripts enclosed?

Answers:

  1. <script…/script>
  2. <?php>…</?>
  3. <?php…?>
  4. <&>…</&>

149. What of the listed below are correct magic methods?

Answers:

  1. __construct(), __destruct(), __put(), __post()
  2. __construct(), __destruct(), __get(), __set()
  3. __init(), __final(), __get(), __set()
  4. __init(), __final(), __put(), __post()

150. How do you create a connection to MySQL database in PHP?

Answers:

  1. mysqliconnect()
  2. mysqli-connect()
  3. mysqli_connect()
  4. sql_connect()

151. Which of the following is used to execute a prepared statement in PHP-MySQL?

Answers:

  1. mysqli_stmt_execute()
  2. mysqli_execute_stmt()
  3. mysqli_query()
  4. mysqli_stmt_bind_param()

152. What is the output of the following code?
$a = “b”;
$b = 22;
echo $$a + 40

Answers:

  1. 22
  2. 40
  3. 62
  4. 0

153. How to get client IP address in a PHP script?

Answers:

  1. $_DOMAIN[‘REMOTE_ADDR’]
  2. $_SERVER[‘REMOTE_ADDR’]
  3. $_SERVER[‘REMOTE_IP_ADRESS’]
  4. $_ENV

154. What is the output of the following code?
try {
$a = 10/0;
echo $a;
} catch (Exception $e) {
echo ‘You cannot divide by ZERO!!’ ;
}

Answers:

  1. You cannot divide by ZERO!!
  2. 10
  3. Warning: Division by zero
  4. 0

155. What is the output of the following code run using PHP 5.6.0 or higher?
const ONE = 1;
class foo {
const TWO = ONE * 2;
const THREE = ONE + self::TWO;
const SENTENCE = ‘The value of THREE is ’.self::THREE;
}
echo foo::SENTENCE . “\n”;

Answers:

  1. The value of THREE is 1
  2. The value of THREE is 12
  3. The value of THREE is 3
  4. The value of THREE is 13

156. Which of these are not a valid data type?

Answers:

  1. String
  2. Bool
  3. Char
  4. Integer
  5. UInt

157. Pick the correct PHP function to rewind the internal array pointer

Answers:

  1. last()
  2. before()
  3. prev()
  4. Integer
  5. previous()

158. Which of the following is the correct keyword in SQL?

Answers:

  1. SELECT
  2. Select
  3. select
  4. SeLeCt
  5. All of the above

159. Which function is used to read a file removing the HTML and PHP tags in it?

Answers:

  1. fgetss()
  2. fgets()
  3. fopen()
  4. file_strip_tags()

160. Which of the following is the correct way to open the file «sample.txt» as read only?

Answers:

  1. open(«sample.txt»);
  2. open(«sample.txt», «read»);
  3. fopen(«sample.txt», «r+»);
  4. fopen(«sample.txt», «r»);

161. Which of the following will return true keeping in view the following code?
function validateDate($date, $format = ‘Y-m-d H:i:s’)
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
Answers:

  1. validateDate(‘2012-02-30 12:12:12’)
  2. validateDate(’30/02/2012′, ‘d/m/Y’)
  3. validateDate(’14:77′, ‘H:i’)
  4. validateDate(‘2012-02-28 12:12:12’)

162. Which function can be used to determine if a file exists?
Note: There may be more than one right answer.

Answers:

  1. is_readable()
  2. file_exists()
  3. feof()
  4. is_file_exists()

163. What is the output of the following code?
class foo {
public $bar = <<<‘EOT’ bar line1 line2 EOT; public function printbar(){ echo $this->bar;
}
}
$myobj = new foo;
$myobj->printbar();
Answers:

  1. bar
  2. bar
    line1
    line2
  3. bar line1 line2
  4. Error

164. Which function is used to delete a file from the server using PHP?

Answers:

  1. unlink()
  2. unset()
  3. delete()
  4. remove_file()

165.What is the output of the following code?
session_start();
$_SESSION[‘logged_in’] = true;
$_SESSION[‘name’] = ‘Jane’;
$_SESSION[‘level’] = 4;
echo session_encode();
Answers:

  1. logged_in|b:1;name|s:4:»Jane»;level|i:4;
  2. Array ( [logged_in] => 1 [name] => Jane [level] => 4
  3. {«logged_in»:true,»name»:»Jane»,»level»:4}
  4. You cannot encode session variables.

166. Which of the following PHP predefined constant is not related to Fatal errors?

Answers:

  1. E_PARSE
  2. E_CORE_ERROR
  3. E_ERROR
  4. E_RECOVERABLE_ERROR

167. What the operator «instanceof» is used for?

Answers:

  1. to determine how many instances a PHP variable has
  2. to determine whether a PHP variable is an instantiated object of a certain class
  3. to make a copy of a PHP variable
  4. none of all listed above

168.Mysqli::autocommit does not work with which of the following table types?

Answers:

  1. InnoDB
  2. BDB
  3. NDB Cluster
  4. MyISAM

169.How do you throw an exception in PHP?

Answers:

  1. throw new Exception(message);
  2. throw Exception(message);
  3. throws new Exception(message);
  4. None of these

170. What is the correct way to add 1 to the $a variable?
Note: There may be more than one right answer.

Answers:

  1. $a=+1
  2. $a++
  3. ++$a
  4. a++

171. What is the output of the following code?
$sentence = «ThiS iS a SenTEnCe»;
echo ucwords($sentence);
Answers:

  1. This Is A Sentence
  2. THIS IS A SENTENCE
  3. this is a sentence
  4. ThiS IS A SenTEnCe

172. Which of the following is true when mail() function returns true?

Answers:

  1. The email is reached to the client’s mail server.
  2. The local mail server (or the SMTP configured in php.ini) accepted the outgoing email for delivery.
  3. The local mail server (or the SMTP configured in php.ini) has sent the email.
  4. None of the above.

173. If you do not want to serialize any of the properties of an object, which PHP function is used to accomplish this task?

Answers:

  1. unserialize()
  2. __wakeup
  3. __sleep

174. What is the problem with the following code?
<?php
$size =$_POST[‘size’];
$query = «SELECT id, name, inserted, size FROM products WHERE size = ‘$size’»;
$result = pg_query($conn, $query);
?>
Answers:

  1. SQL query syntax is not correct as a result database error will be thrown
  2. Variable $size is not validated and escaped therefore SQL Injection can be executed
  3. «pg_query» is not a PHP operator
  4. $_POST is not correct a Superglobal variable

175. Which of the following statements invoke the exception class?

Answers:

  1. throws new Exception();
  2. throw new Exception();
  3. new Exception();
  4. new throws Exception();

176. Which directive determines how the session information will be stored?

Answers:

  1. save_data
  2. session_save
  3. session.save_data
  4. session.save_handler

177.Which Content Type header need to be set to send an HTML mail in PHP?

Answers:

  1. ‘Content-type: html; charset=iso-8859-1’ . «\r\n»;
  2. ‘MIME-Version: 1.0’ . «\r\n» — пока это
  3. ‘Content-type: text/html; charset=iso-8859-1’ . «\r\n»
  4. ‘Content-type: application/html; charset=iso-8859-1’ . «\r\n»

178. What does the following statement do with respect to the errors that will get displayed?
error_reporting(E_ALL & ~E_NOTICE);

Answers:

  1. Report all errors
  2. Report only NOTICE messages
  3. Report all errors other than NOTICE messages

179. What will be the output of executing the following code?
<?php
class Foo {
private function printName($name) {
print_r($name);
}
}
$a = new Foo();
$a->printName(‘James’);
?>
Answers:

  1. James
  2. Fatal error: Call to private method Foo::printName() from context …
  3. Notice: Undefined variable: a
  4. Fatal error: Call to undefined method Foo::printName()

180.Which of the following has Object Oriented and Procedural support as well as supports prepared statements?

Answers:

  1. PDO
  2. MYSQLi
  3. MYSQL

181. Which of the following is used to pick one or more random entries out of an array?

Answers:

  1. array_random()
  2. array_rand()
  3. shuffle()
  4. rand()

182.Which of the following function is used to read the content of a file?

Answers:

  1. fopen()
  2. fread()
  3. filesize()
  4. file_exists()

183. Which function is used to get the number of arguments passed to the function?

Answers:

  1. func_num_args()
  2. $_GET
  3. func_get_args_num()
  4. func_get_arg()

184. Which of the following is not a valid keyword with respect to exception handling in PHP?

Answers:

  1. try
  2. catch
  3. throw
  4. throws

185. What is the output of the following code?
$foo = 10;
$bar = ’10’;
if ($foo === $bar){
echo ‘I ran’;
}
Answers:

  1. I ran
  2. Nothing is output
  3. TRUE
  4. Error

186. What piece of code would you use to obtain an array of response headers for a given URL, indexed by their respective names?

Answers:

  1. get_headers($url);
  2. get_header($url);
  3. get_headers($url,1);

187. What piece of code would you use to obtain an array of response headers for a given URL, indexed by their respective names?

Answers:

  1. get_headers($url);
  2. get_header($url);
  3. get_headers($url,1);

188.Which of the following is true with respect to Flyweight design pattern in PHP?

Answers:

  1. All the methods of the class should be private.
  2. This pattern is used when you need only a small number of instances of same type.
  3. Using this pattern consumes a lot of memory.
  4. Instances of a class which are identical are shared in an implementation instead of creating a new instance of that class for every instance.

189. What is true about get_defined_vars() function?

Answers:

  1. It returns the array of all the defined variables.
  2. It returns the array of all the defined variables of a function.
  3. It returns all the $_POST variables only.
  4. It returns all the $_GET variables only

190.How many elements are in the array created by the following line of code:
$array = array (true => ‘5’, 1 => ‘6’);

Answers:

  1. 1
  2. 2
  3. 3
  4. 4

191.Which function can convert a comma separated string into an array using a single call?

Answers:

  1. strtoarray
  2. explode
  3. extract
  4. substr

192.Which is the correct way to profile a PHP function (without relying on 3rd party libraries and/or PHP extensions)?

Answers:

  1. $start = microtime();
    functionToProfile();
    $end = microtime();
    $duration = $end — start;
  2. $start = time();
    functionToProfile();
    $end = time();
    $duration = $end — start;
  3. $start = microtime(true);
    functionToProfile();
    $end = microtime(true);
    $duration = $end — start;
  4. $start = date(‘U’);
    functionToProfile();
    $end = date(‘U’);
    $duration = $end — start;

193.Which of the following are valid in PHP?
Note: There may be more than one right answer.

Answers:

  1. $_23
  2. ${«foobar»}
  3. &$foo
  4. $23_foobar
  5. $foobar

194. What will be the output of the following code?
$time = strtotime (‘2016-01-01’);
echo date (‘d-m-y H:i:s:u’, $time);
Answers:

  1. 16-01-01 00:00:00:00
  2. 01-01-16 00:00:00:000000
  3. 01-01-2016 00:00:00:000000
  4. 01-01-16 00:00:00:00

195.Which of the following is not related with respect to calculating the size of a file?Answers:

  1. filesize()
  2. cURL
  3. file_exists()
  4. stat()

196.After the following query is executed using PHP, which function can be used to count the number of rows returned?
SELECT * from students
Note: There may be more than one right answer.
Answers:

  1. mysqli_affected_rows()
  2. mysqli_num_rows()
  3. mysqli_use_result()
  4. mysqli_fetch_lengths()

197.Which of the following is not correct with respect to Authentication using CURL?
Answers:

  1. CURL can be used to authenticate a user.
  2. CURL can be used to send form data using both GET and POST methods.
  3. CURL can not be used to authenticate a user as it can only be used to access and read webpage data.
  4. CURL can be used for HTTP Basic Authentication.

198.Which of the following method of Exception class returns source filename ?
Answers:

  1. getMessage()
  2. getCode()
  3. getFile()
  4. getLine()

199. Which of the following is true about the singleton design pattern?
Answers:

  1. A singleton pattern means that a class will only have a single method.
  2. A singleton pattern means that a class can have only one instance object.
  3. A singleton pattern means that a class has only a single member variable.
  4. Singletons cannot be implemented in PHP.

200. What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.
Answers:

  1. Use mysql_query() and variables: for example: $input = $_POST[‘user_input’]; mysql_query(«INSERT INTO table (column) VALUES (‘» . $input . «‘)»);
  2. Use PDO prepared statements and parameterized queries: for example: $input= $_POST[«user-input»] $stmt = $pdo->prepare(‘INSERT INTO table (column) VALUES («:input»); $stmt->execute(array(‘:input’ => $input));
  3. Use mysql_query() and string escaped variables: for example: $input= $_POST[«user-input»] $input_safe = mysql_real_escape_string($input); mysql_query(«INSERT INTO table (column) VALUES (‘» . $input. «‘)»);
  4. Use mysql_query() and variables with a blacklisting check: for example: $blacklist = array(«DROP»,»INSERT»,»DELETE»); $input= $_POST[«user-input»] if (!$array_search($blacklist))) mysql_query(«INSERT INTO table (column) VALUES (‘» . $input. «‘)»);

201. Which of the following methods should be used for sending an email using the variables $to, $subject, and $body?
Answers:

  1. mail($to,$subject,$body)
  2. sendmail($to,$subject,$body)
  3. mail(to,subject,body)
  4. sendmail(to,subject,body)

202. Which of the following will print out the PHP call stack?
Answers:

  1. $e = new Exception; var_dump($e->debug());
  2. $e = new Exception; var_dump($e->getTraceAsString());
  3. $e = new Exception; var_dump($e->backtrace());
  4. $e = new Exception; var_dump($e->getString());

203. What will be the output of the following code?
<?php
var_dump (3*4);
?>

Answers:

  1. int(3*4)
  2. int(12)
  3. 3*4
  4. 12
  5. None of the above

204. Which of the following will start a session?
Answers:

  1. session(start);
  2. session();
  3. session_start();
  4. login_sesion();

205. Which of the following is incorrect with respect to separating PHP code and HTML?
Answers:

  1. Use an MVC design pattern.
  2. As PHP is a scripting language, HTML and PHP cannot be separated.
  3. Use any PHP template engine e.g: smarty to keep the presentation separate from business logic.
  4. Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to views.

206. Which of the following will read an object into an array variable?
Answers:

  1. $array_variable = get_object_vars($object);
  2. $array_variable = (array)$object;
  3. $array_variable = array $object;
  4. $array_variable = get_object_vars $object;

207. Which of the following is correct about Mysqli and PDO?
Answers:

  1. Mysqli provides the procedural way to access the database while PDO provides the object oriented way.
  2. Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.
  3. MySQLi prevents SQL Injection whereas PDO does not.
  4. MySQLi is used to create prepared statements whereas PDO is not.

208. Which of the following characters are taken care of by htmlspecialchars?
Answers:

  1. <
  2. >
  3. single quote
  4. double quote
  5. &
  6. All of these

209. Which function can be used to delete a file?
Answers:

  1. delete()
  2. delete_file()
  3. unlink()
  4. unlink()
  5. fdelete()
  6. file_unlink()

210. What would occur if a fatal error was thrown in your PHP program?
Answers:

  1. The PHP program will stop executing at the point where the error occurred.
  2. The PHP program will show a warning message and program will continue executing.
  3. The PHP program will show a warning message and program will continue executing.
  4. Since PHP is a scripting language so it does not have fatal error.
  5. Nothing will happen.

211. Which function will suitably replace ‘X’ if the size of a file needs to be checked?
$size=X(filename);

Answers:

  1. filesize
  2. size
  3. sizeofFile
  4. getSize

212. Which statement will return true?
Answers:

  1. is_numeric («200»)
  2. is_numeric («20,0»)
  3. is_numeric («$200»)
  4. is_numeric («.25e4»)
  5. None

213. What will be the output of the following code?
<?php
$xmlFile = «<root><css><element><csstag><title>background-color</title><value>#FFF</value></csstag><csstag><title>color</title><value>#333</value></csstag><csstag><title>font-family</title><value>Verdana, Geneva, sans-serif</value></csstag></element></css></root>»;
$xml = simplexml_load_string($xmlFile);
foreach($xml->css as $css) {
echo (string) $css->element[‘id’].»{«;
foreach($xml->css->element->csstag as $tag) {
$temp = $tag->title.»: «.$tag->value.»;»;
echo $temp;
}
echo «}»;
}
?>

Answers:

  1. syntax error
  2. background-color: #FFF;color: #333;font-family: Verdana, Geneva, sans-serif;
  3. parse error;
  4. {background-color: #FFF;color: #333;font-family: Verdana, Geneva, sans-serif;}

214. What is the output of the following code?
<?php
echo «<pre>»;
$array1 = array(
«1»=>»a»,
«2»=>»b»,
«3»=>»c»
);
$array = array_flip($array1);
print_r($array);
echo «</pre>»;
?>

Answers:

  1. Array
    (
    [1] => a
    [2] => b
    [3] => c
    )
  2. Array
    (
    [a] => 1
    [b] => 2
    [c] => 3
  3. Array
    (
    [0] => c
    [1] => b
    [2] => a
    )
  4. Array
    (
    [0] => 1
    [1] => 2
    [2] => 3
    )

215. Suppose $var=1;
Which of the following will produce a Boolean value of true?
?


Answers:

  1. var_dump(isset($var))
  2. var_dump(is_null($var))
  3. var_dump(empty($var))
  4. var_dump(defined($var))

37,642 total views, 27 views today