Saturday 26 March 2016

Upwork PHP Test Answers 2015-16




1. 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
  6.  
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 one of the following is not an encryption method in PHP?
Answers:
  1. crypt()
  2. md5()
  3. sha1()
  4. bcrypt()
19. 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

20. What is the string concatenation operator in PHP?
Answers:
  1. +
  2. ||
  3. .
  4. |||
  5. None of these

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

22. 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
23. 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]);
24. Which function can be used to delete a file?
Answers:
      a. delete()
      b. delete_file()
      c. unlink()
      d. fdelete()
      e. file_unlink()

25.   Which one is correct?
  1. $s = fwrite (“a string here”);
  2. $s = fwrite ($fp,”a string here”);
  3. $s = fwrite (“a string here”,$fp);
  4. non of the above
26.   Which of the following set of operations is not valid in PHP 5?
  1. >, >=
  2. =,==
  3. !==,!==
  4. +=, *=
27.   Late PHP version support remote file accessing for the functions:
  1. include()
  2. include_once()
  3. require_once()
  4. All of the above
  28.  What will be the output of the following script?
$count=50;
function Argument()
{
$count++;
echo $count;
}
Argument()
?>
  1. It will print 50
  2. It will print 51
  3. It will print 52
  4. It will print 1
29.   which of the following are used for code reuse?
  1. Loops
  2. functions
  3. Database
  4. include files
 30.   You need to keep an eye on the existing number of objects of a given class without introducing a non-class varibale. which of the following makes this happen?
  1. Add a member varibale that gets incremented in the default constructer and decremented the destructer.
  2. Add a local variable that gets incremented in each constructer and decremented in the desructer
  3. Add a static member variable that gets incremented in each constructer and decreented in the destructor
  4. This cannot be accomplished since the creation of objects is being done dynamically via “new”




No comments:

Post a Comment