Upwork PHP Test-2015

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

Answers:

a. fclose

b. fopen

c. fwrite

d. fgets

e. fappend

 

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

Answers:

a. 1

b. 20

c. 21

d. 23

e. 34

 

3. Does PHP 5 support exceptions?

Answers:

a. Yes

b. No

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

Answers:

a. mail($to,$subject,$body)

b. sendmail($to,$subject,$body)

c. mail(to,subject,body)

d. sendmail(to,subject,body)

 

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

Answers:

a. static

b. global

c. session_register()

d. None of these

 

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

Answers:

a. function_exists()

b. has_function()

c. $a = “function to check”; if ($a ()) // then function exists

d. None of these

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

Answers:

a. <

b. >

c. single quote

d. double quote

e. &

f. All of these

 

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

Answers:

a. $array_variable = get_object_vars($object);

b. $array_variable = (array)$object;

c. $array_variable = array $object;

d. $array_variable = get_object_vars $object;

 

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

Answers:

a. private $type = ‘moderate’;

b. internal $term = 3;

c. public $amnt = ‘500’;

d. protected $name = ‘Quantas Private Limited’;

 

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

Answers:

a. __FUNCTION__

b. __TIME__

c. __FILE__

d. __NAMESPACE__

e. __CLASS__


 

 

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

Answers:

a. int(3*4)

b. int(12)

c. 3*4

d. 12

e. None of the above

12. Which of the following will start a session?

Answers:

a. session(start);

b. session();

c. session_start();

d. login_sesion();


 

 

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

Answers:

a. multipart/form-data

b. multipart

c. file

d. application/octect-stream

e. None of these


 

 

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

Answers:

a. crypt()

b. md5()

c. sha1()

d. bcrypt()

 

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

Answers:

a. join_st

b. implode

c. connect

d. make_array

e. None of these

 

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

Answers:

a. delete()

b. delete_file()

c. unlink()

d. fdelete()

e. file_unlink()

 

17. What is the string concatenation operator in PHP?

Answers:

a. +

b. ||

c .

• |||

• None of these

 

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

Answers:

a. __call,__get,__set

b. _get,_set,_load

c. __get,__set,__load

d. __overload

 

19. Which of the following will store order number (34) in an 'OrderCookie'?

Answers:

a. setcookie(“OrderCookie”,34);

b. makeCookie(“OrderCookie”,34);

c. Cookie(“OrderCookie”,34);

d. OrderCookie(34);

20. 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:

a. memory_limit = 128M

b. limit_memory = 128M

c. memory_limit: 128M

d. limit_memory: 128M

 

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

Answers:

a. A singleton pattern means that a class will only have a single method.

b. A singleton pattern means that a class can have only one instance object.

c. A singleton pattern means that a class has only a single member variable.

d. Singletons cannot be implemented in PHP.

 

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

Answers:

a. Mysqli provides the procedural way to access the database while PDO provides the object oriented way.

b. Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.

c. MySQLi prevents SQL Injection whereas PDO does not.

d. MySQLi is used to create prepared statements whereas PDO is not.

 

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

Answers:

a. s.sendmail($EmailAddress, [$MessageBody], msg.as_string())

b. sendmail($EmailAddress, “Subject”, $MessageBody);

c. mail($EmailAddress, “Subject”, $MessageBody);

d. <a href=”mailto:$EmailAddress”>$MessageBody</a>

 

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

Answers:

a. $arr[$newkey] = $oldkey; unset($arr[$oldkey]);

b. $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]);

c. $newkey = $arr[$oldkey]; unset($arr[$oldkey]);

d. $arr[$newkey] = $oldkey.GetValue(); unset($arr[$oldkey]);

 

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

Answers:

a. $e = new Exception; var_dump($e->debug());

b. $e = new Exception; var_dump($e->getTraceAsString());

c. $e = new Exception; var_dump($e->backtrace());

d. $e = new Exception; var_dump($e->getString());

 

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

Answers:

a. The PHP program will stop executing at the point where the error occurred.

b. The PHP program will show a warning message and program will continue executing.

c. Since PHP is a scripting language so it does not have fatal error.

d. Nothing will happen.

 

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

Answers:

a. Use an MVC design pattern.

b. As PHP is a scripting language, HTML and PHP cannot be separated.

c. Use any PHP template engine e.g: smarty to keep the presentation separate from business logic.

d. Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to views.

 

28. For the following code:
<?php
function Expenses()
{
function Salary()
{
}
function Loan()
{
function Balance()
{
}
}
}
?>
Which of the following sequence will run successfully?

Answers:

a. Expenses();Salary();Loan();Balance();

b. Salary();Expenses();Loan();Balance();

c. Expenses();Salary();Balance();Loan();

d. Balance();Loan();Salary();Expenses();

 

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

Answers:

a. Use mysql_query() and variables: for example: $input = $_POST[‘user_input’]; mysql_query(“INSERT INTO table (column) VALUES (‘” . $input . “‘)”);

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

c. 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. “‘)”);

d. 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. “‘)”);

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.