Upwork PHP Test 2018

Upwork PHP Test Answers 2018

40 Answered Test Questions:

1)The PDD_MYSQL Datasource name(DSN) is composed of the following     elements?
a)user_pass
b)db_table
c)dbname
d)unix_socket
e)charset

2)Which of the following statements is incorrect with regards to                 inheritance in PHP?
a)A class can only have a single parent,i.e. cannot extend more than one class.
b)A class can both extend another class as well as implementan an interface.
c)A class can implement more than one interface.
d)A class can extend more than one class.

3)Which MIME type needs to be used to send attachment in mail?
a)text/html
b)text/plain
c)application/mixed
d)multipart/mixed

4)Which function can be used to determine if a file exists? (choose all that  apply)
a)is_readable()
b)file_exists()
c)feof
d)is_file_exists()

5)What is the output when the following code is executed?
  <?php 
  function myFun($a){
  if (!$a) {
  throw new Eception ("Value init.");
  }
  return 3/$a;
  }
  try {
  echo myFun (3). "/n";
  } catch (exception $e) {
  echo'Caught exception' , $e->getMessage(), "n;
  }finally{
  echo "second\n";
  }
echo"hello PHP example\n;
a)Value init.3
  first 
  1
  second
  Hello PHP example
b)Value init.1
  first
  3 
  second
  Hello PHPexample
c)1
  first
  3
  second
  Hello PHP example
d)Value init.1
  first
  5
  Second
  Hello PHP Example

6)The following functions can be used from Expection class?
a)getline()
b)getCode By Name()
c)get Message()
d)getide()
e)getraceASString()

7)Xdebug is a PHP___, the information which Xdebug provides is about stack and functions with full parameter for user defined fuctions, memory allocation an support for infinite recursions.
a)Framework
b)Library
c)Extension
d)Class

8)What is the output of the following code?
  <?php
  function y ($v) {
  echo $v;
  }
  $w = "y";
  $w("z");
  $w = "x;
  ?>
a)x
b)y
c)z
d)<error>

9)How you can send Multiply email recipients all go into the address field, with commas  separating?
a)$headers = "From:sender@example.com/r/n';
  $recipients = "abc@hotmail.com,xyz@gmail.com";
  mail($recipients, "This is the subject", "This is the mail body". $headers);
b)$mailsend = mail ("receiver@recipthost, abc@hotmail.com,xyz@gmail.com,       "the sample   

subject
c)$address = "abc@hotmail.com";
  $Subject = "I want a car';
  $body = 'Smith";
  $mailsend = mail("$address","4Subject","$body.");
  print("$mailsend");
d)All of the above.

10)By default, every database connection opened by a script is either explicitly closed  by the user during runtime or released _ at the end of the script?
a)automatically
b)manually
c)server-side
d)sql

11)You can extend the exception base class, but you can not override any of teh preceding methods because they are declared as:
a)protected
b)final
c)Static
d)private

12)Which is true about the curl_setop() ApI?
a)PHP does not provide such an API.
b)It sets multiply options for a cURL transfar.
c)It executes the curl command.
d)It sts one option for a cURL transfer.

13)Which of the following file modes is used to write into a file at the end of the existing content, and creat the file does not exist?
a)r+
b)w+
c)a
d)x

14)What would occur if a fatal error was thrown in your PHP program?
a)The PHP program will stop executing at the point where the error occurred.
b)The PHP program will show a warning mesage and program will continue            executing. 
c)Since PHP is a scripting language so it does not have fatal error.
d)Nothing will happen.

15)What is the fastest way to insert an item $item into the specified position $position of the array $array?
a)array_insert()
b)array_splice()
c)array_merge() and array_slice()
d)PHP does not have any built- in function that can do this :the source array will   have  
  to be copied ans $item inserted in to the required position:
  $n   =0;
  foreach ($array as $key =$val) {
  if ($n == $position) {
  $target [] =$item;
  }
  ++$n;
  $target [$key] = $val
  }

16)Whicho of the following will print out the PHP call stack?
a)$e = new Exception;
  var_dump($e->debug());
b)$e = new Expection;
  var_dump($e->get TraceAsstromg());
c)$e = new exception;
  var_dump ($e->backtrace());
d)$e=new Expection;
  var_dump($e->getstring());

17)Which is a called funciton or object method taking the following               parameters?
a)&buffer
b)&errormsg
c)buflen
d)Stream
e)All of the above

18)What is the correct way to send a SMTP (Simple Mail Transfar                   Protocol) email using PHP?
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>

19)How do you access result se meta data?
a)<?php
  $mysqli = new mysqli ("abcs., "user" , "password", "database");
  if ($mysqli->connect_error) {
  echo "Failed to connect to MySQL: (".$myqli->connect_error.")" . $mysqli->   

 connect_error;
  }
  $tres = $mysqli=>query("Select 1 AS_one, "Hello" AS_two form DuaL");
  var _dump(.$res->fetch_fieldss(1));
b)<?php
  $mysqli = new ("abcs.com", "usaer", "password", "database");
  if ($mysqli-> connect_errno){
  echo "failed to connect to MYSQL: (" . $mysqli-> connect _error. ") ".$mysqli-.   

connect_error;
  }
  $res = $mysqli=>query("SELECT 1 AS_one, "Hello" As _two From DUAL");
  var_dump($res->fetch_fields()):
  ?>
c)<?php
  $mysqli = new mysqli("abcs.com" , "user" , "password", "database");
  if ($mysqli->connect_errno) {
  echo "Failed to connect to MySQl: (" . $mysqli->connect_errno. ") ". $mysqli->   

connect_error;
  }
  $res= $mysqli-> query("SELEct 1 As, "Hello' AS _ two From Dual");
  var_dump (res->$fetch_fileds());
  ?>
d)<?php
  $mysqli = new mysqli ("abcs.com" , "user", "password", "database");
  if ($mysqli=> connect_errno) {
  echo"failed to connect to MYSQL: (". $mysqli=>connect_errno. ") ".$mysqli-  

>connect_error;
  }
  $tres = $mysqli=>query("SELECT 1 AS _one, "Hello' AS _ two From Dual");
  var-dump($res=>fetch_field());
  ?>
e)<?php
  $mysqli = new mysqli ("abcs.com" , "user", "password", "database");
  if ($mysqli=> connect_errno) {
  echo"failed to connect to MYSQL: (". $mysqli=>connect_errno. ") ".$mysqli-  

>connect_error;
  }
  $tres = $mysqli=>query("SELECT 1 AS , "Hello' AS _ two From Dual");
  var-dump($res=>fetch_field());
  ?>
f)<?php
  $mysqli = new mysqli ("abcs.com" , "user", "password", "database");
  if ($mysqli=> connect_errno) {
  echo"failed to connect to MYSQL: (". $mysqli=>connect_errno. ") ".$mysqli-  

>connect_error;
  }
  $tres = $mysqli=>query("SELECT 1 AS _one, "Hello' AS _ two From Dual");
  var-dump($res=>fetch_field(0));
  ?>

20)What will be the output of executing the following code?
   <?php
   class foo{
   private function printNAme($name) {
   print_r($name);
    }
   }
  $a = new foo();
  $a-> printName('James');
  ?>
a)James
b)Fatal error: Call to private method foo:: printName() from context...
c)Notice: Underfined variable:a
d)Fatal error: Call to underfined method Foo:: printName()



1 comments:

idiot where is answers?

Balas