Core php Upwork Test 2017


We don’t guarantee that all provided answers are correct.

Placing the ____ symbol before a function tells PHP to suppress any errors generated by that function.

  • !
  • @
  • #
  • $

Which function is used to destroy a variable or object?

  • destroy()
  • clear()
  • unset()
  • reset()

Giving the following array:
$array=array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);
Which one of the following will print 2?

  • echo array_search(‘green’, $array);
  • echo in_array(‘green’, $array);
  • echo array_key_exists(2, $array);
  • echo array_search(‘red’, $array);

Which MIME type need to be used to send attachment in mail?

  • text/html
  • text/plain
  • application/mixed
  • multipart/mixed

How to create a database with PHP in MySQL Server?

  • create_db(‘database’);
  • mysql_db(‘database’);
  • mysql_create_db(‘database’);
  • mysql_server_create_db(‘database’);

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

  • 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

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?

  • r+
  • w+
  • a
  • x

Which is wrong with the following code?

curl_setopt($ch, CURLOPT_url, “”);
curl_setopt($ch, CURLOPT_HEADER, 0);

  • There is nothing wrong with the code
  • The CURL resources $ch has not been created using the curl_init() method
  • The $ch variable needs to be initialized as $ch=null;
  • The code cause will cause a parse error

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

  • The PHP program will stop executing at the point where the error occurred
  • The PHP program will show a warning message and program will continue executing
  • Since PHP is a scripting language so it does not have fatal error
  • Nothing will happen

Which of the following will detect which request type was used (GET, POST, PUT OR DELETE)?
</strong >Answer

  • $method = explode(“/”, substr(@$_SERVER[‘PATH_INFO’], 1));
  • $method = $_GET[‘REQUEST_METHOD’];
  • $method = $_SERVER[‘REQUEST_METHOD’];
  • $method = $_POST[‘REQUEST_METHOD’];

Which statement is not correct?
$x = null;

  • empty($x) return TRUE
  • is_null($x) return FALSE
  • isset($x) return FALSE
  • None of the above

What is the correct way to send an SMTP (Simple Mail Transfer Protocol) email using PHP?

  • s.sendmail($EmailAddress, [$MessageBody], msg_as_string());
  • sendmail($EmailAddress, “Subject”, $MessageBody);
  • mail($EmailAddress, “Subject”, $MessageBody);
  • $MessageBody

Which of the following are valid MySQLi Configuration options? (Choose all that apply)
Note: There may be more than one right answer

  • mysqli.allow_persistent
  • mysqli.rollback_on_cached_size
  • mysqli.default_port
  • mysqli.default_socket

Where can protected property or method be accessed?

  • It can only be accessed within the class itself
  • It can be accessed outside of the class
  • It can only be accessed within the class itself or in descendant classes
  • It can no be accessed anywhere

How to rename a file in PHP?

  • file_rename(oldname, newname)
  • file(oldname, newname)
  • rename(oldname, newname)
  • file_change(oldname, newname)

Which method is used to tweak an Oject’s cloning behavior?

  • clone()
  • __clone()
  • _clone()
  • object_clone()

You can extend the exception class, but you cannot override any of the preceding methods they are declared as:

  • protected
  • final
  • static
  • private

The ___ statement takes all the text/code/markup/that exists in the specified file and copies it into the file that uses the statement.(Check all that apply)

  • require
  • include
  • get
  • add

Which in-built function will add a value to end of an array?

  • array_unshift()
  • into_array()
  • inend_array()
  • array_push()

What is the correct syntax of mail() function in PHP?

  • mail($to,$subject,$message,$headers)
  • mail($from,$to,$subject,$message)
  • mail($to,$from,$subject,$message)
  • mail($to,$from,$message,$headers)

The PDO_MYSQL Data Source Name(DSN) is composed of the following elements?
Note: There may be more than one right answer

  • user_pass
  • db_table
  • dbname
  • unix_socket
  • charset

What will be the output of executing the following code?
class Person{
proctected $name;
public function __construct($name){
$this->name = $name;
public function getName(){
return $this->name;
$person = new Person(“Foo”);
echo $person -> getName();

  • Nothing will be printed on-screen
  • Foo
  • Syntax error on line $this->name=$name
  • Fatal error on line $this->name=$name

Which function can be used to determine if a file exists?
Note: There may be more than one right answer.

  • is_readable()
  • file_exists()
  • feof()
  • is_file_exists()

Which of these is not a valid SimpleXML Parser method?

  • simplexml_import_dom()
  • simplexml_import_sax()
  • simplexml_load_file()
  • simplexml_load_string()

What will be the output of above code?
<?php $arr = array(‘Hello’, ‘World!’, ‘Beautiful’, ‘Day!’) echo implode(” “, $arr); ?>

  • HelloWorld!BeautifulDay!
  • ‘Hello’, ‘World!’, ‘Beautiful’, ‘Day!’
  • Hello World! Beautiful Day!
  • No Output

Which of the following will produce a value of “83” as its output?

  • echo intval(“0123”, 8);
  • echo (int) 083
  • echo (int) 123
  • echo intval(“0123”);

How to remove white-space from the beginning and end of $string variable?

  • cut($string);
  • removeSpace($string);
  • shorten($string);
  • trim($string);

Which of the following is used to send mail in PHP?

  • send_mail(to, subject, headers, parameters);
  • mail(to, subject, headers, parameters);
  • mail::(to, subject, headers, parameters);
  • mail_to(to, subject, headers, parameters);

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

  • 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. «‘)»);

What are methods in PHP?
Note: There may be more than one right answer

  • Individual action that an object will be to perform are defined within the class as methods?
  • An individual instance of the data structure defined by a class
  • These are the function defined inside a class and are used to access object data
  • There are the function in which the objects of the class are saved

PHP ___ are used to validate and sanitize external input?

  • Cookies
  • Filters
  • Exceptions
  • Files

Which of the following is not a valid cURL parameter in PHP?


PHP currently offers the following function for searching strings using POSIX-style regular expression?
Note: There may be more than one right answer

  • sql_regcase()
  • eragi_replace()
  • ereg_replace()
  • spliti()
  • erag()

What is the output of the following code?
<?php function abc(){
function xyz() {
return abc();
echo xyz();

  • abc
  • __FUNCTION__
  • xyz
  • <empty.output>

What will be output of the following code?
$x = 1;
while ($x <=3)){
echo “$x, “;

  • 1
  • 1, 2, 3,
  • 1, 2, 3
  • No Output

How can you connect with a MySQL Server in PHP?

  • database_connect(server, username, password)
  • mysql_connect(host, username, password)
  • mysql(server, username, password)
  • connect(server, username, password)

Which of these is not a valid PHP XML DOM method?

  • geElementByName()
  • removeChild()
  • geElementById()
  • appendChild()

Which function is used to read a file removing the HTML and PHP tags in it?

  • fgetss()
  • fgets()
  • fopen()
  • file_strip_tags()

What is the meaning of the system message, Allowed memory size of bytes exhausted?

  • The avaliable RAM memory is exhausted
  • The avaliable disk memory is exhausted
  • The avaliable readomly memory is exhausted
  • The maximum memory allocated in php.ini is exhausted

With regards to the “static” keyword in PHP, which of the following statement is false?

  • The $this can be used inside any static method
  • Static properties may only be intialized using literal or a constant
  • A property declared as static can not be accessed with an instantiated class object
  • A static variable or method can be accessed without requiring instantiation of class


  1. Wonderful post however I was wanting to know if you could write a litte more onn this topic?
    I’d be very thankful if you could elaborate a little bit more.
    Many thanks!


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.