Thursday, 30 October 2014

Update oDesk PHP Test Question and Answer



1.Does PHP 5 support exceptions?
1.     Yes
2.     No
2.For the following code: <?php function Expenses() { function Salary() { } function Loan() { function Balance() { } } } ?> Which of the following sequence will run successfully?
1.     Expenses();Salary();Loan();Balance();
2.     Salary();Expenses();Loan();Balance();
3.     Expenses();Salary();Balance();Loan();
4.     Balance();Loan();Salary();Expenses();
3.What function should you use to join array elements with a glue string?
1.     join_st
2.     implode
3.     connect
4.     make_array
5.     None of these
4.What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.
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. "')");
5.What is the best way to change the key without changing the value of a PHP array element?
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]);
6.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?
1.     memory_limit = 128M
2.     limit_memory = 128M
3.     memory_limit: 128M
4.     limit_memory: 128M
7.What is the correct way to send a SMTP (Simple Mail Transfer Protocol) email using PHP?
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>
8.What is the string concatenation operator in PHP?
1.     +
2.     ||
3.  .
4.     |||
5.     None of these
9.What will be the output of the following code? <? echo 5 * 6 / 2 + 2 * 3; ?>
1.     1
2.     20
3.     21
4.     23
5.     34
10.What enctype is required for file uploads to work?
1.     multipart/form-data
2.     multipart
3.     file
4.     application/octect-stream
5.     None of these

0 comments:

Post a Comment