Saturday, March 12, 2016

UPWORK PHP TEST Questions & ANSWER "Me Easily Done This Job"






           Upwork PHP Test 2016

LATEST UPWORK QUESTION(All PHP Questions With Answer Present Here, Share With Your Friends)

MCQ's TEST .... "4 Options, Choose One Of Them"

QUESTION::
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?
Ans= 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?
<?php
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?
$size=X(filename);
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();
$cl->clsName();
Insurance::clsName();
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?
<?php
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)
{
if(is_array($value))
{ 
DisplayArray($value);
}
else 
{
echo $value . ” “;
}
}
}
DisplayArray($array);
?>

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;
var_dump($e->getTraceAsString());

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?
<?php
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”,
“bar”,
“baz”);
for($i = 0; $i < count($arr); $i++)
{
$item = $arr[$i];
}
echo “<pre>”;
print_r($item);
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?
Ans= $REMOTE_ADDR

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

40.What is the output the following code?
<?php
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:
<?php
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;
         var_dump($e->getTraceAsString());

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.


49.Question:
Which Of the following is Not A PHP Magic Constant?
Answers:
• __FUNCTION__
• __TIME__
• __FILE__
• __NAMESPACE__
• __CLASS__



50 Answered Test Questions:

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

Answers:
• Use mysql_query() and variables: for example: $input = $_POST['user_input']; mysql_query("INSERT INTO table (column) VALUES ('" . $input . "')");
• 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));
• 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. "')");
• 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. "')");

QUESTION::
Which of the Following Environment Variables is Used to Fetch the IP Address of the user in your PHP application?

    a:    $IP_ADDR
    b:    $REMOTE_ADDR_USER
    c:    $REMOTE_ADDR
    d:    $IP_ADDR_USER
    Answer:
    c: $REMOTE_ADDRQUESTION::

QUESTION::
You need to check the size of a file in php function.
            $size=X(filename);
            Which function will suitably replace “X”?
            a:    filesize
            b:    size
            c:    sizeofFile
            d:    getSize
            Answer:
            a: filesize

Question: :
How would you start a session?

a. session(start);
b. session();
c. session_start();
d. begin_sesion();



QUESTION::
Which of the following is not a PHP magic constant?

Answers:
• __FUNCTION__
• __TIME__
• __FILE__
• __NAMESPACE__
• __CLASS__


QUESTION::
Which of the following will read an object into an array variable?

Answers:
$array_variable = get_object_vars($object);
• $array_variable = (array)$object;
• $array_variable = array $object;
• $array_variable = get_object_vars $object;
 

QUESTION::

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

Answers:
• <
• >
• single quote
• double quote
• &
• All of these
Which of the following is true about the singleton design pattern?

Answers:
• A singleton pattern means that a class will only have a single method.
• A singleton pattern means that a class can have only one instance object.
• A singleton pattern means that a class has only a single member variable.
• Singletons cannot be implemented in PHP.

QUESTION::
QUESTION::

 What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.
Answers:
• Use mysql_query() and variables: for example: $input = $_POST['user_input']; mysql_query("INSERT INTO table (column) VALUES ('" . $input . "')");
• 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));
• 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. "')");
• 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. "')");


With what encoding does chr () work?

a. ASCII

b. UTF-8

c. UTF-16

d. Implementation dependent

e. None of the above

Ans : a



QUESTION::

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

Ans: B (A singleton means that a class can have only one instance)

QUESTION::

Which of the following attributes is needed for file upload via a form?

Ans: enctype=”multipart/form-data”>

QUESTION::

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

Ans: Session_register()

QUESTION::

 Which of the following is correct about Mysqli and PDO?

Ans: (A)

QUESTION::

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

Ans:  (B)

QUESTION::

Which of the following statements is incorrect?

Ans: (C)

QUESTION::

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

Ans: (A)

QUESTION::

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

Ans: (B)

QUESTION::

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

Ans: (B)

QUESTION::

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

Ans: (B)

QUESTION::

What will be the output of the following code?

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

Ans: (B)

QUESTION::

What is wrong with the following code?

Ans: (D)

QUESTION::

Which of the following is not a valid API?

Ans: (A)

QUESTION::

 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?

Ans: (C) (D)

QUESTION::

<?php $arr = array(“foo”,              “bar”,              “baz”); for ($i = 0; $i < count($arr); $i++) {    $item = $arr[$i];  } echo “<pre>”; print_r($item); echo “</pre>”; ?>

Ans: (D)

QUESTION::

 Which is true about the curl_setopt() API?

Ans:  (D) (B)

QUESTION::

What will be the output of following code?  $a = 10; echo “Value of a = $a”;

Ans:  (A)

QUESTION::

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?

Ans: (B)

QUESTION::

Which of the following will return the extension of a file name?

Ans: (C)



QUESTION::

Que: <?php $str=”Hello”;  $test=”lo”;  echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;  ?>

Ans: (D)

QUESTION::

 Which of the following is not a valid API?

Ans:  (A)

QUESTION::

 <?php   $string1 = “abcdefg”;   $string2 = “abcfghi”;   $position = strspn($string1 ^ $string2, “\0”);   echo $position; ?>

Ans:  (C)

QUESTION::

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

Ans:  (B)

QUESTION::

What is the correct way to count the number of parameters given in the URL by a post operation?

Ans: (C)

QUESTION::

What is the meaning of the system message, “Allowed memory size of <number> bytes exhausted”?

Ans: (D)

QUESTION::

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

Ans: (B)

QUESTION::

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

Ans: (F)

QUESTION::

 which of the following will print out the php call stack

Ans: (B)

QUESTION::

which of the following is true about the singleton design pattern

Ans: (B)

 QUESTION::

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

Ans: A


QUESTION::

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

Ans: A , stop execution at the point where the error occurred

 QUESTION::
Which function can be used to delete a file?

Answers:

• delete()

• delete_file()

• unlink()

• fdelete()

• file_unlink()QUESTION::
Which of the following is useful for method overloading?

Answers:

• __call,__get,__set

• _get,_set,_load

• __get,__set,__load

• __overloadWhich of the following is correct about Mysqli and PDO?

Answers:

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

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

• MySQLi prevents SQL Injection whereas PDO does not.

• MySQLi is used to create prepared statements whereas PDO is not.Should assert () be used to check user input?

a. yes

b. no

Ans : b



1 comment: