Ads by Google
Get This Adsense Pop-up Window


Friday 30 June 2017

Upwork Test Answers | PHP Upwork Test Answers 2019

  1. which MIME type needs to be used to send an attachment in mail ?
  •    multipart/mixed
  1. What is the output of  the following code ?
class Foo {private $foo;
protected $bar;
public $test;
public function  __construct()
{
$this->foo = 1;
$this->bar = 2;
$this ->test = 3;
}
}
print_r(   (array) new Foo );
  •   Array([Foofoo]=>1 [*bar]=>2[test]=>3)
  1. By default, every database connection opened by a script is either explicitly closed by the user during run time of released__________ at the end of the script.
  •  Server-side
  1. Which magic method is used to implement overloading in PHP ?
  •  __call
  1. What will be the output of following code ?
<?php   $i = 016;echo $i /2;
?>
  •   7
  1. 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
  1. Which of the following statements is incorrect with respect to inheritance in PHP?
  •  A Class can extend more than one class.
  1. You can extend the exception class, but you cannot override any of the preceding methods they are declared as :
  • final
  1. What is the correct syntax of mail() function in php ?
  •  mail($to,$subject,$message,$headers)
  1. What is the fastest way to insert an item $item into the specified position $position of the array $array ?
  •  array_merge() and array_slice()
  1. Which of the following MySQL fetch constants imply: if the columns are returned into the array having both a numerical index and the field name as the array index ?
  • Ans. MYSQL_BOTH
  1. Which function is used to get  the number of arguments passed to the function ?
  •  func_num_args()
  1. What is the output of the following code ?
<?phpfunction abc(){
return_FUNCTION_;
}
function xyz()
{
return abc();
}
echo xyz();
?>
  •  abc
  1. �  Which Function can be used to determine if a file exist? (choose all that apply)
  •    is_readable(),
file_exists(),
is_file_exists()
  1. What will be the output of following code
<?phpclass A {
public static function foo() {
static::who();
}
public static function who(){
echo __CLASS__.”\n”;
}
}
class B extends A {
public static function test(){
A::foo();
parent::foo();
self::foo();
}
public static function who() {
echo __CLASS__. “\n”;
}
}
Class C extends B {
public static function who(){
echo __CLASS__.”\n”;
}
}
C::test();
?>
  •  ACC
  1. Which of the following will print out the PHP call stack ?
  •   $e=new Exception;
var_dump($e->getTraceAsString())
  1. What is the correct way to send an SMTP(Simple Mail Transfer Protocol) email using PHP?
  •  sendmail($EmailAddress,”Subject”,”$MessageBody);
  1. The PDO_MYSQL Data Source Name(DSN) is composed of the following elements ?
  • dbname
unix_socket
charset
  1. Which is true about the curl_setopt() API ?
  •  It sets one option for cURL transfer
  1. What will be the output of the following PHP code ?
<?php$var=300;
$int options  = array(“options”=>array(“min_range”=>0,”max_range”=>256));
if(!filter_var($var,FILTER_VALIDATE_INT, $int_options))
echo(“Integer is not valid”);
else
echo(“Integer is valid”);
?>
  • Integer is not valid
  1. Which function is used to read a file removing the HTML and PHP tags in it ?
  • fgetss()
  1. What will the output of following code :-
<?phpclass BaseClass {
public function test() {
echo “BaseClass::test() called\n”;
}
final public function moreTesting() {
echo “BaseClass::moreTesting() called \n”;
}
}
class ChildClass extends BaseClass {
public function moretesting(){
echo “ChildClass::moreTesting() called\n”;
}
}
$obj = new ChildClass;
$obj->moreTesting();
?>
  • Results in Fatal error : Cannot override final method
BaseClass::moreTesting();
  1. What will happen if a fatal error was thrown in your PHP program ?
  • The PHP program will stop executing at the point where the error
occured.
  1. Which of the following code can be used to send email to multiple recipients ?
  • $recipients = array(‘recipient1@domain.com’,’receipient2@domain.com);
mail($recipients,$subject,$messege,$headers);
  1. Which of the following functions belong to Exception class ? (Choose all that apply)
  •    getLine()
getTraceAsString();
  1. Which of the following are valid MySQLi Configuration options ? (Choose all that apply ?
  •    mysqli.allow_persistent
mysqli.default_port
mysqli.default_socket
  1. Which is the best approach to parse HTML and extract structured information from it ?
  •  Use an XML parser (as simpleXML) and XPath queries if available.
  1. What is the output of the following code ?
<?phpfunction y($v) {
echo $v;
}
$w = “y”;
$w (“z”);
$w = “x”;
?>
  •  z
  1. Xdebug is a PHP____________, the information which Xdebug provides is about stack and functions with full parameter for user defined functions, memory allocation and support for infinite recursions.
  •  Extension
  1. See the example class code below
class ExampleClass{
public $val = 5 ;
function &getValNum()
{
return $this->val;
}
}
which of the following one can be used for Return by reference ?
  •   $obj = new ExampleClass();
$myVal = $obj->getValNum();
  1. What is the output of following code ?
function myFun($a) {if(!$a){
throw new Exception(‘Value init.’);
}
return 3/$a;
}
try {
echo myfun(3) .”\n”;
}catch (Exception $e){
echo ‘Caught exception: ‘, $e->getMessage(), “\n”;
} finally {
echo “first\n”;
}
try{
echo myFun(1).”\n”;
} catch (Exception $e) {
echo ‘Caught exeption:’, $e->getMessage(),”\n”;
}  finally {
echo “second\n”;
}
echo “Hello PHP Example\n”;
  •  1 first 3 second Hello PHP Example
  1. What is true about ini_set(‘memory_limit’,’-1’) ?
  • parse error
  1. what is the correct way to read-in multiple values from an array ?
  •  list($x,$y,$z) = array(7,8,9);
  1. What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection ?
  •  Use PDO prepared statements and parameterized queries
  1. Which of the following is the right MIME to use as a Contant Type for JSON data ?
  • application/json
  1. Which of the following is the correct way to convert a variable from a string to an integer ?
  •  $number_variable = (int)$string_variable;
  1. There are a number of mysqlnd plugins already available. These include
  •  PECL/mysqlnd_pscache – Prepared Statement Handle Cache plugin
PECL/mysqlnd_sip – SQL Injection Protection Plugin
PECL /mysqlnd_uh – User Handler Plugin
PECL/mysqlnd_qc – Query Cache Plugin
  1. What will be the  output of executing the following code ?
  •  Fata error : Call to private method Foo:: printName() from context
  1. When designing classes with UML, a class at its core has the following components ? (choose all that apply)
  •  Methods, Attributes
  1. Which of the following would show an error in php ?
  •  @echo 1
  1. What would be the output of the following code ?
$str = “0011110000bsts11100”;echo trim($str,’010s’);
  •  bst
  1. What would be the output of the I and II sample codes:
I)$a  = array();
$b = $a;
$b[‘foo’] = 42;
echo $a[‘foo’];
II)
$a = new StdClass();
$b = $a;
$b->foo = 42;
echo $a->foo;
  •  Null 42
  1. Which of the following is not a Super Global variable in PHP ?
  •  None of the above
  1. Which of the following would produce an error :
$currentDT = new DateTime();
  •  $currentDT->getTimezone(new DateTimeZone(‘UTC’));
  1. Which statement is incorrect ?
  •  unset() forces the PHP garbage collector to immediately.
  1. which of the following is not related to garbage collection in PHP ?
  • gc_cycles()
  1. which statement is not correct ?
  2. $x = null;
  • empty($x) return TRUE
  1. What would be the output of the following code ?
  2. $parts = parse_url(“https://example.com/test/1234?testing&val&id=1&&=23&row=4”);
    parse_str($parts[‘query’],$query);
    echo count($query);
  • 4
  1. Which of the following is not the correct way to create an empty object in PHP ?
  • $obj = new stdClass();
  1. Which function is used to destroy a variable or object ?
  • unset()
  1. What will be the output of the following code ?
  2. $arr = array(“THEY”,”WE”,array(“I”,”YOU”),”YOUR”);
    echo(count($arr,1));
  • 6
  1. Which statement is not correct ?
  • PHP_EOL – The correct ‘End of Line’ symbol for this platform.
  1. Which method is used to tweak an oject’s cloning behavior ?
  • clone()
  1. How do you access result set meta data ?

<?php
$mysqli = new mysqli(“example.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 _one, ‘Hello’ AS _two FROM DUAL”);
var_dump($res->fetch_fields());
?>
  1. Which of the following will decode a JSON variable $json to an object ?
  2. $json = ‘{“abc”:1,”def”:2,”ghi”:3,”jkl”:4,”mno”:5}’;
  • both of above ($object = json_decode($json); and $object = json_decode($json,true);)
  1. Choose the correct option to force redirect from http to https :
  • RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  1. What will be the output of executing the following code ?
  2. <?php
    class Foo {
    private function printName($name) {
    print_r($name);
    }
    }
    $a = new Foo();
    $a->printName(‘James’);
    ?>
  • Fatal error: Call to private method Foo::printName() from context…
  1. What will be the output of the below code ?
  2. $tmp = “Dragon%%Ball%%z%”;
    $arr = explode(‘%’,trim($tmp));
    echo count($arr);
  • 6
  1. Which of the following options will fall to remove the element “y” when placed in the blank space in the below sample code
  2. $row = array(0=>”x”,1=>”y”,2=>”z”,3=>”w”)
    print_r($row)
  • array_diff($row,[“y”]);

  1. Which of the following is the correct option to get a numerically indexed array containing all defined timezone identifiers in PHP

  • DateTimeZone::listIdentifiers(DateTimeZone::UTC);

  1. What will be the output of the following code ?
  2. echo(1234==’1234 test’ ? ‘Equal’ : ‘Not equal’);
  • Equal
  1. After the following query is executed using PHP, which function can be used to count the number of rows returned ?(choose all that apply)
  2. SELECT * from students
  • mysqli_affected_rows()
mysqli_numrows()

No comments:

Post a Comment