Monday 27 August 2018

PHP Test Upwork and oDesk 2018 Answers

upwork PHP Questions & answers created as per the need of the freelancers and also for the student who wants to know something extra in PHP. we start to create Upwork PHP test 2108.It includes the basics level to advance level PHP question that made you perfect.
Following are the Upwork PHP test. Go and secure Your life.
1. Which HTML type needs to be used to send an attachment in mail?
  • A) Text/Html
  • B)Text/plain
  • C) Application/mixed
  • D) multipart <===/mixed
2. Which of the following are valid MySQLi configuration?(multiple selection)
  • A)mysqli.allow_persistent<===
  • B)mysqli.default_socket<===
  • C)mysqli.default_port<===
  • D)mysqli.rollback_on_cached_size
3. What is the correct way to send SMTP mail using PHP?
  • A)s.sendmail($EmailAddress,[$MessageBody],msg.as_string())
  • B)sendmail($EmailAddress,”subject”,”$MessageBody”)
  • C)mail($EmailAddress,”subject,””$messageBody”)<===
  • D)$MessagwBody
4. Which Symbol tells PHP to support any errors generated by any function?
  • A)!
  • B)#
  • C)@<===
  • D)$
5.Which statement takes all text/code/markup tgat exists in the specified file and copies it into the file that uses statement?
  • A)Get
  • B)Add
  • C)include
  • D)require<===

6.Which is not a valid PHP XML api?
  • A)libxml_clear_errors()
  • B)libxml_get_errors()
  • C)libxml_use_internal_errors()
  • D)libxmlError()<===
7.Which is the correct syntax of mail() function in php?
  • A)mail($to,$subject,$message,$headers)<===
  • B)mail($from,$to,$subject,$message)
  • C)mail($to,$from,$subject,$message)
  • D)mail($to,$from,$message,$headers)
8.How can we Rename a file in php?
  • A)File_rename(oldname,newname)
  • B)File(oldname,newname)
  • C)rename(oldname,newname)<===
  • D)File_change(oldname,newname)
9.Where can protected property or method be accessed?
  • A)It can only accessed with in the class itself
  • B)It can be accessed outside of the class
  • C)It can only accessed within the class itself or in desscendant classes
  • D)It can not accessed anywhere
10.How can you connect with a MySQL Server in PHP?
  • A)database_connect(server, username, password)
  • B)mysql(server, username, password)
  • C)connect(server, username, password)
  • D)mysql_connect(host, username, password)
11.Which of the following is not a valid CURL parameter in PHP?
  • A)CURLOPT_RETURNTRANSFER
  • B)CURLOPT_GET
  • C)CURLOPT_POSTFIELDS
  • D)CURLOPT_POST
12.Which function is used to destroy a variable or object?
  • A)destroy()
  • B)clear()
  • C)reset()
  • D)unset()
13.What are methods in PHP?
  • A)Individual action that an object will be to perform are defined within the class as methods.
  • B)An individual instance of the data structure defined by a class
  • C)These are the function defined inside a class and are used to access object data
  • D)There are the function in which the objects of the class are saved
14.Which of the following is true about the singleton design pattern?
  • A)A singleton pattern means that a class will only have a single method
  • B)A singleton pattern means that a class has only a single member variable
  • C)A singleton pattern means that a class can have only one instance object
  • D)Singletons cannot be implemented in PHP
15.How to create a database with PHP in MySQL Server?
  • A)create_db(‘database’);
  • B)mysql_db(‘database’);
  • C)mysql_create_db(‘database’);
  • D)mysql_server_create_db(‘database’);
16.Giving the following array:
$array=array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);
  • A)echo in_array(‘green’, $array);
  • B)echo array_key_exists(2, $array);
  • C)echo array_search(‘green’, $array);
  • D)echo array_search(‘red’, $array);
17. What will happen if fatal error occurs in your program ?
  • A)Since PHP is a scripting language so it does not have fatal error
  • B)The PHP program will stop executing at the point where the error occurred
  • C)The PHP program will show a warning message and program will continue executing
  • D)Nothing will Happen
18.Which in-built function will add a value to end of an array?
  • A)array_unshift()
  • B)into_array()
  • C)inend_array()
  • D)array_push()
19.How can short tags be enabled in PHP?
  • A)set the value of short_open_tag=on in the php.ini file and restart the web server
  • B)set the value of short_tag=on in the php.ini and restart the web server
  • C)set the value of short_tags=on in the php.ini file
  • D)no one
20.Which of the following is not a valid DOM method in php?
  • A)loadXMLFile()
  • B)loadXML()
  • C)loadHTMLFile
  • D)loadHTML
21.Which of the following file modes is used to write into a file at the end of the existing content, and create the file if the file does not exist?
  • A)r+
  • B)w+
  • C)a
  • D)X
22.Which method is used to tweak an object’s cloning behavior?
  • A)clone()
  • B)_clone
  • C)_clone()
  • D)object_clone()
23.<?php $arr = array(‘Hello’, ‘World!’, ‘Beautiful’, ‘Day!’)
echo implode(” “, $arr);
?>
What will be the output?
  • A)Helloworld!BeautifulDay!
  • B)‘Hello’, ‘World!’, ‘Beautiful’, ‘Day!’
  • C)Hello World! Beautiful Day!
  • D)Syntax error
24.Which of the following will produce a value of “83” as its output?
  • A)echo (int) 083
  • B)echo intval(“0123”, 8);
  • C)echo (int) 123
  • D)echo intval(“0123”);
25.What is difference detween “echo” and “print” in php?
  • A)echo can take multiple parameter, while print can only take a single parameter
  • B)Print has a return value of 1 can be used in expressions whereas “echo” has a void return type.
  • C)print perform slightly slower than echo
  • D)there is no any difference
26.Which of these is not a valid SimpleXML Parser method?
  • A)simplexml_import_dom()
  • B)simplexml_import_sax()
  • C)simplexml_load_file()
  • D)simplexml_load_string()
27.How to remove white-space from the beginning and end of $string variable?
  • A)cut($string);
  • B)removeSpace($string);
  • C)shorten($string);
  • D)trim($string);
28.Which function can be used to determine if a file exists?
  • A)is_readable()
  • B)file_exists()
  • C)feof()
  • D)is_file_exists()
29.The extent to which proximate procedures are related to one another is known ?
  • A)Coupling
  • B)Balancing
  • C)Cohesion
  • D)co-relation
30.Which of the following will detect which request type was used (GET, POST, PUT OR DELETE)?
  • A)$method = explode(“/”, substr(@$_SERVER[‘PATH_INFO’], 1));
  • B)$method = $_GET[‘REQUEST_METHOD’];
  • C)$method = $_SERVER[‘REQUEST_METHOD’];
  • D)$method = $_POST[‘REQUEST_METHOD’];
31.You can extend the exception class, but you cannot override any of the preceding methods they are declared as:
  • A)protected
  • B)final
  • C)static
  • D)private
32.The PDO_MYSQL Data Source Name(DSN) is composed of the following elements?
  • A)user_pass
  • B)db_table
  • C)dbname
  • D)unix_socket
  • E)charset
33.Which statement is not correct?
$x=null;
  • A)empty($x) return TRUE
  • B)is_null($x) return FALSE
  • C)isset($x) return FALSE
  • D)None of the above
34.Which is used to validate and sanitize external input?
  • A)cookies
  • B)filters
  • C)exceptions
  • D)files
35.Which function is used to read a file removing the HTML and PHP tags in it?
  • A)fgetss()
  • B)fgets()
  • C)fopen()
  • D)file_strip_tags()
36.____ are like variables except that once they are defined they cannot be changed or undefined?
  • A)String
  • B)Integers
  • C)Constants
  • D)Array
37.with regards to the “static” keyword in php, which of the following statement is false?
  • A)The $this variable can be used inside any static method
  • B)static properties may only be initialized using a literal or a constant.
  • C)A property declared as static can not accessed with an instantiated class object.
  • D)A static variable or method can be accessed without requiring instantiation of the class
38.How do you check if a variable is empty?
  • A)isset($variable)
  • B)empty($variable)
  • C)is_empty()
  • D)no_value()
39.What of the listed below are correct magic methods?
  • A)_construct(),_destruct(),_put(),_post()
  • B)_construct(),_destruct(),_get(),_set()
  • C)_init(),_final(),_get(),_set()
  • D)_init(),_final(),_put(),_post()
40.Which of the following is the correct way to create an array in php?
  • A)$animals=array(cat,Dog,Horse);
  • B)$animals=array(“cat”,”Dog”,”Horse”);
  • C)$animals=array[“cat”,”Dog”,”Horse”];
  • D)$animals=”cat”,”Dog”,”Horse”;
41.What is the output of the following?
<?php
echo ucwords(“i had 3three cars”);
?>
  • A)i had 3three cars
  • B)I had 3three cars
  • C)I Had 3three Cars
  • D)I Had 3Three Cars
42.What is the output of the following?
<?php
$i = 1;
while ($i <= 3){
echo “$i,”;
$i++;
}
?>
  • A)1,2,3
  • B)1,2,3,
  • C)1 2 3
  • D)syntax error
43.Which of the following is not the correct way to create an empty object in PHP?
  • A)$obj=(object)[];
  • B)$obj= new class();
  • C)$obj = new stdClass();
  • D)$obj= new\stdClass;
44.Which of the following functions is not related to garbage collection in PHP?
  • A)gc_collection_cycles()
  • B)gc_cycles()
  • C)gc_disable()
  • D)gc_enable()
45.What will be the output of the following code?
$var1=’/’;
$var2=’/&%#!’;
echo (strpos($var1,$var2)? ‘Found’ : ‘Not found’);
  • A)Not found
  • B)Found
  • C)syntax error
  • D)Function not found
46.Which of the following is not a valid PHP XML DOM method?
  • A)getElementsByTagName
  • B)removeChild()
  • C)getElementsById()
  • D)appendChild()
47.What wil be the output of the following code?
echo(1234 == ‘1234 test’ ? ‘Equal’ : ‘Not Equal’);
  • A)Not Equal
  • B)Equal
  • C)None
  • D)Error
48.What wil be the output of the following code?
$arr = array(“They” , “We” ,array(“I” , “You”), “Your”);
echo (count($arr,1));
  • A)2
  • B)4
  • C)5
  • D)6
49.What is the wrong with the following code?
<?php
curl_setopt($ch,CURLPOT_URL, “http;//www.example.com/”);
curl_setopt($ch,CURLPOT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
  • A)There is nothing wrong with the code.
  • B)The curl resource $ch has not been created using the curl_init() method.
  • C)The $ch variable needs to be initialized as $ch=null;
  • D)The code will cause a parse error.
50.Which of the following method is triggered when invoking inaccessible methods in a static context?
  • A)_call()
  • B)__call()
  • C)_callStatic()
  • D)__callStatic()
does php 5 support exceptions?
for the following code: <?php function expenses() { function salary() { } function loan() { function balance() { } } } ?> which of the following s...
what enctype is required for file uploads to work?
what function should you use to join array elements with a glue string?
what is the best practice for running mysql queries in php? consider the risk of sql injection.
what is the best way to change the key without changing the value of a php array element?
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?
what is the correct way to send a smtp (simple mail transfer protocol) email using php?
what is the string concatenation operator in php?
what will be the output of the following code? <? echo 5 * 6 / 2 + 2 * 3; ?>
what will be the output of the following code? <?php var_dump (3*4); ?>
what would occur if a fatal error was thrown in your php program?
which function can be used to delete a file?
which of the following characters are taken care of by htmlspecialchars?
which of the following is correct about mysqli and pdo?
which of the following is incorrect with respect to separating php code and html?
which of the following is not a file-related function in php?
which of the following is not a php magic constant?
which of the following is true about the singleton design pattern?
which of the following is used to maintain the value of a variable over different pages?
which of the following is useful for method overloading?
which of the following methods should be used for sending an email using the variables $to, $subject, and $body?
which of the following variable declarations within a class is invalid in php?
which of the following will check if a function exists?
which of the following will print out the php call stack?
which of the following will read an object into an array variable?
which of the following will start a session?
which of the following will store order number (34) in an 'ordercookie'?
which one of the following is not an encryption method in php?
given the following array: $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); which one of the following will print 2?
what is the output of the following code?
<?php
echo 0x500;
?>
which function will suitably replace 'x' if the size of a file needs to be checked? $size=x(filename);
which of the following is the correct way to check if a session has already been started?
which of the following cryptographic functions in php returns the longest hash value?
which of the following is not a valid api?
what is the difference between the float and the double type in php?
what is wrong with the following code?
<?php
curl_setopt($ch, curlopt_url, "http://www.example.com/");
curl_setopt($ch, curlopt_header, 0);
curl_exec($ch);
curl_close($ch);
?>
which of the the following are php file upload-related functions?
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?
what is the correct php command to use to catch any error messages within the code?
what will be the output of the following code?
<?php
var_dump (3*4);
?>
what is the correct syntax of mail() function in php?
which of the following methods is used to check if an array is associative or numeric?
what will be the output of the following code?
<?
$a = 3;
print '$a';
?>
which of these is not a valid simplexml parser method?
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?
what is the meaning of the system message, "allowed memory size of <number> bytes exhausted"?
should assert() be used to check user input?
which of the following functions is not used in debugging?
what will be the output of the following code?
<?
$foo = 5 + "10 things";
print $foo;
?>
which of the following environment variables is used to fetch the ip address of the user in a php application?
which of the following is true about posting data using curl in php?
which of the following regular expressions can be used to check the validity of an e-mail addresss?
which of the following is not a predefined constant?
what is the output of the following code?
<?php
  function abc()
  {
    return __function__;
  }
  function xyz()
  {
    return abc();
  }
  echo xyz();
?>
which of the following file modes is used to write into a file at the end of the existing content, and create the file if the file does not exist?
what is the difference between die() and exit() in php?
which of the following is not a valid dom method in php?
what will be the output of the following code?
<?php
$str="hello";

$test="lo";

echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;

?>
what would be the output of the following code?
<?php
$arr = array("foo",
             "bar",
             "baz");
for ($i = 0; $i < count($arr); $i++) { 
  $item = $arr[$i]; 
}
echo "<pre>";
print_r($item);
echo "</pre>";
?>
which of the following will produce a value of "83" as its output?
what is the best way to load a file that contains necessary functions and classes?
what will be the output of the following code?
<?php
echo 30 * 5 . 7;
?>
which of the following is false about curl?
what is the output of the following code?
<?php
  $array = array("1","2","3","4");
  $variable = end(array_keys($array));
  echo $variable;  
?>
which of the following are not considered boolean false?
what is the fastest way to insert an item $item into the specified position $position of the array $array?
what will be the output of the following code?
<?
$a = (1 << 0);
$b = (1 << 1);

echo ($b | $a) << 2 ;
?>
with regards to the "static" keyword in php, which of the following statements is false?
what will be the output of the following code? class person { protected $name; public function __construct($name) { $this->name = $name; } public function getname() { return $this->name; } } $person = new person("foo"); echo $person->getname();
which of the following printing construct/function accepts multiple parameters?
what will be the output of the following code? $var = 10; function fn() { $var = 20; return $var; } fn(); echo $var;
which of the following is not a valid php.ini parameter with respect to file uploading?
which of the following is true regarding the str_replace() function in php?
which of the following is not a valid xdebug configuration setting?
what is "empty()"?
which of the following statements is incorrect?
which of the following is not related to debugging in php?
what will be the output of the following code?
<?php
$a = (1 << 0);
$b = (1 << $a);
$c = (1 << $b);

echo ($c || $b) << 2 * $a | $a;
?>
what is the output of the following code?
<?php

function
vec_add (&$a, $b)
{
    $a['x'] += $b['x'];
    $a['y'] += $b['y'];
    $a['z'] += $b['z'];
}

$a = array (x => 3, y => 2, z => 5);
$b = array (x => 9, y => 3, z => -7);

vec_add (&$a, $b);

print_r ($a);

?>
which of the following will not return an array containing all normal latin alphabet characters (a-z)?
which of these is not a valid php xml api?
which line would move the internal pointer to the end of an array?
if you are given two dates in this form: start date: 2007-03-24 end date: 2009-06-26 which code snippet finds the difference between these two in the following form: 2 years, 3 months and 2 days php > 5.3
what is the difference between $_server['http_host'] and $_server['server_name']?
which of the following is a ternary operator?
what is the output of the following php code snippet?
<?php

$var = "testing module";
$statement = 'this is a $var';
echo ($statement);

?>
what is the difference between $a == $b and $a === $b in php?
when comparing two arrays, what is the difference between "==" and "==="?
which of the following variables are supported by the 'str_replace()' function?
which of the following is not a valid curl parameter in php?
which of the following is the right mime to use as a content type for json data?
what is the output of the following code?
<?php
  echo "<pre>";
  $array = array("red","green","blue");
  $last_key = end(array_keys($array));
  foreach ($array as $key => $value) {
      if ($key == $last_key) {
      echo "a<br>";
      } else {
      echo "b<br>";
      }
  }
?>
which of the following is not a valid php parser tag?
what is the output of the following code? echo '1'.print(2) + 3;
which statement will return true?
within the phpdoc standard, what is the correct way of "doc commenting" the code?
which of the following statements is incorrect, with regards to inheritance in php?
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 values in the array?
what is meant by synchronous server calls within php's curl features?
what will be the output of following code?
<?php
$x = 10;
function foo() {
    $x = 20;
    echo $x;
    global $x;
    echo $globals['x'];
    echo $x;
}
foo();
echo $x;
?>
which of the following code snippets has the most appropriate headers to force the browser to download a csv file?
is the ||= operator present in php?
which of the following features are supported in php5?
which of the following is correct with regard to echo and print?
which of the following will return the extension of a file name?
which of the following functions is not related to garbage collection in php?
what will be the output of the following code?
<?php
</script>
?>
which of the following is the best way to get the index(es) of the highest value(s) in an array?
what will be the output of the following code?
<?php
print null == null;
?>