upwork php test 2015

This is latest post upwork php test 2015

In this show only answer, not show all 4 option.

1.What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.
Ans= Use PDO prepared statement and parameterized queries:
for example:
$input = $_POST["user-input"]
$stmt = $pdo->prepare('INSERT INTO table (column) VALUES (":input")');
$stmt->execute(array(':input' => $input));

2.Should assert() be used to check user input?
Ans= NO

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

4.which function is used to remove the first element of an array?
Ans= array_shift

5.Which of the following are useful for method overloading?
Ans=__get, __set, __call, __callStatic

6.Which will be output of the following code?
var_dump (3*4);
Ans= int(12)

7.Which of the following is the correct way to check if a session has already been started?
Ans= if (session_id()) echo 'session started';

8.Which function will suitably replace 'X' if the size of a file needs to be checked?
Ans= filesize

9.Which of the following methods should be used for sending an email using the variables #to, $subject, and $body?
Ans= mail($to,$subject,$body)

10.Which of the following is correct about Mysqli and PDO?
Ans= Mysqli can only be used to access Mysql database while PDO can be used to access any DBMS.

11.Which of the following is true about the singleton design pattern?
Ans= A singleton pattern means that a class can have only one instance object.

12.Which of the following cryptographic functions in PHP returns the longest hash value?
Ans= sha(1)

13.What is the correct PHP command to use to catch any error messages within the code?
Ans= set_erroe_handler('error_handler');

14.What will be the output of the following code?
$a = 3;
print '$a';
Ans= none of these

15.Given the following array:
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
Which one of the following will print 2?
Ans= echo array_search('green', $array);

16.Which of the following will start session?
Ans= session_start();

17.Which of the the following are PHP file upload-related functions?
Ans= is_uploaded_file() and move_uploaded_file()

18.What is the correct way to send a SMTP email using PHP?
Ans= mail($EmailAddress, "Subject", $MessageBody);

19.Consider the following class:
class Insurance
function clsName()
echo get_class($this);
$cl = new Insurance();
Which one the following lines should be commented to print the class name without errors?
Ans= Line 10

20.Which of the following is not a valid API?
Ans= trigger_print_error()

21.Which of the following characters are taken care of by htmlspecialchars?
Ans= All of these

22.What is the output of the following code?
function abc()
return __FUNCTION__;
function xyz()
return abc();
echo xyz();
Ans= abc

23.Which of the following is used to maintain the value of a variable over different pages?
Ans= session_register()

24.What would occur if a fatal error was thrown in your PHP program?
Ans= The PHP program will stop executing at the point where the error occurred.

25.Which of the following is not a PHP magic constant?
Ans= __TIME__

26.Which function can be used to delete a file?
Ans= unlink()

27.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 value of in the array?
Ans= <?php
$array = array(array(141, 151, 161), 2, 3, array(101, 202, 303));

function DisplayArray($array)
foreach($array as $value)
echo $value . " ";

28.Which of the following is not a file-related function in PHP?
Ans= fappend

29.Which of the following will print out the PHP call stack?
Ans= $e = new Exception;

30.What is difference between die() and exit() in PHP?
Ans= die() accept a string as its optional parameter which is printed before the application terminates; exit() accept ad integer as its optinal parameter which is passed to the 
operating system as the exit code.

31.What is the correct syntax of mail() function in PHP?
Ans= mail($to,$subject,$message,$headers)

32.Which of the following function is not used in debugging?
Ans= fprintf()

33.Which of the following is not a valid DOM method in PHP?
Ans= loadXMLFile()

34.Which of the following variable declarations within a class is invalid in PHP?
Ans= internal $term = 3;

35.What will be the output the following code?
echo false;
Ans= Nothing

36.What is the output the following code?
echo '1' .print(2) + 3;
Ans= 511

37.What would be the output of the following code?
$arr = array("foo",
for($i = 0; $i < count($arr); $i++)
$item = $arr[$i];
echo "<pre>";
echo "</pre>";
Ans= baz;

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

39.What will be the output the following code?
echo 30 * 5 . 7;
Ans= 1507

40.What is the output the following code?
echo (2) . (3 * (print 3));
Ans= 323

41.What enctype is required for file uploads to work?
Ans= multipart/form-data

42.What is the string concatenation operator in php?
Ans= .

43.For the following code:
function Expenses()
function Salary()

function Loan()
function Balance()
Which is the followung sequence will run successfully?
Ans= Expenses();Salary();Loan();Balance();

44.What is the correct use of the constant, PHP_EOL?
Ans= For writing a new line that is cross-platform compatible.

45.What is the best way to load a file that contains necessary functions and classes?
Ans= include($filename);

46.Which of these is not a valid SimpleXML Parser method?
Ans= simplexml_import_sax

47. Which of the following will print out the PHP call stack?
Ans= $e = new Exception;

48. Which of the following will read an object into an array variable?
Ans= $array_variable = get_object_vars($object); 

Hello friends, If you found new question of PHP upwork test, so you can send me via contact us. And you will got answer as soon as.