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?
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’);
$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?
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;
$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”);
?>
<?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++;
}
?>
<?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’);
$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’);
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));
$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);
?>
<?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?
Yes 100.0%
No 0.0%
for the following code: <?php function expenses() { function salary() { } function loan() { function balance() { } } } ?> which of the following s...
Expenses();Salary();Loan();Balance(); 98.0%
Salary();Expenses();Loan();Balance(); 0.0%
Expenses();Salary();Balance();Loan(); 0.0%
Balance();Loan();Salary();Expenses(); 1.0%
what enctype is required for file uploads to work?
multipart/form-data 100.0%
multipart 0.0%
file 0.0%
application/octect-stream 0.0%
None of these 0.0%
what function should you use to join array elements with a glue string?
join_st 0.0%
implode 100.0%
connect 0.0%
make_array 0.0%
None of these 0.0%
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 . "')"); 1.0%
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)); 85.0%
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. "')"); 10.0%
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. "')"); 1.0%
what is the best way to change the key without changing the value of a php array element?
$arr[$newkey] = $oldkey; unset($arr[$oldkey]); 0.0%
$arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); 100.0%
$newkey = $arr[$oldkey]; unset($arr[$oldkey]); 0.0%
$arr[$newkey] = $oldkey.GetValue(); unset($arr[$oldkey]); 0.0%
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?
memory_limit = 128M 100.0%
limit_memory = 128M 0.0%
memory_limit: 128M 0.0%
limit_memory: 128M 0.0%
what is the correct way to send a smtp (simple mail transfer protocol) email using php?
s.sendmail($EmailAddress, [$MessageBody], msg.as_string()) 0.0%
sendmail($EmailAddress, "Subject", $MessageBody); 5.0%
mail($EmailAddress, "Subject", $MessageBody); 94.0%
<a href="mailto:$EmailAddress">$MessageBody</a> 0.0%
what is the string concatenation operator in php?
+ 0.0%
|| 1.0%
. 98.0%
||| 0.0%
None of these 0.0%
what will be the output of the following code? <? echo 5 * 6 / 2 + 2 * 3; ?>
1 0.0%
20 0.0%
21 100.0%
23 0.0%
34 0.0%
what will be the output of the following code? <?php var_dump (3*4); ?>
int(3*4) 0.0%
int(12) 100.0%
3*4 0.0%
12 0.0%
None of the above 0.0%
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. 100.0%
The PHP program will show a warning message and program will continue executing. 0.0%
Since PHP is a scripting language so it does not have fatal error. 0.0%
Nothing will happen. 0.0%
which function can be used to delete a file?
delete() 0.0%
delete_file() 0.0%
unlink() 100.0%
fdelete() 0.0%
file_unlink() 0.0%
which of the following characters are taken care of by htmlspecialchars?
< 0.0%
> 0.0%
single quote 0.0%
double quote 0.0%
& 0.0%
All of these 100.0%
which of the following is correct about mysqli and pdo?
Mysqli provides the procedural way to access the database while PDO provides the object oriented way. 12.0%
Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS. 87.0%
MySQLi prevents SQL Injection whereas PDO does not. 0.0%
MySQLi is used to create prepared statements whereas PDO is not. 0.0%
which of the following is incorrect with respect to separating php code and html?
Use an MVC design pattern. 2.0%
As PHP is a scripting language, HTML and PHP cannot be separated. 97.0%
Use any PHP template engine e.g: smarty to keep the presentation separate from business logic. 0.0%
Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to views. 0.0%
which of the following is not a file-related function in php?
fclose 0.0%
fopen 0.0%
fwrite 0.0%
fgets 0.0%
fappend 100.0%
which of the following is not a php magic constant?
__FUNCTION__ 0.0%
__TIME__ 100.0%
__FILE__ 0.0%
__NAMESPACE__ 0.0%
__CLASS__ 0.0%
which of the following is true about the singleton design pattern?
A singleton pattern means that a class will only have a single method. 0.0%
A singleton pattern means that a class can have only one instance object. 100.0%
A singleton pattern means that a class has only a single member variable. 0.0%
Singletons cannot be implemented in PHP. 0.0%
which of the following is used to maintain the value of a variable over different pages?
static 0.0%
global 4.0%
session_register() 95.0%
None of these 0.0%
which of the following is useful for method overloading?
__call,__get,__set 100.0%
_get,_set,_load 0.0%
__get,__set,__load 0.0%
__overload 0.0%
which of the following methods should be used for sending an email using the variables $to, $subject, and $body?
mail($to,$subject,$body) 100.0%
sendmail($to,$subject,$body) 0.0%
mail(to,subject,body) 0.0%
sendmail(to,subject,body) 0.0%
which of the following variable declarations within a class is invalid in php?
private $type = 'moderate'; 0.0%
internal $term = 3; 100.0%
public $amnt = '500'; 0.0%
protected $name = 'Quantas Private Limited'; 0.0%
which of the following will check if a function exists?
function_exists() 100.0%
has_function() 0.0%
$a = "function to check"; if ($a ()) // then function exists 0.0%
None of these 0.0%
which of the following will print out the php call stack?
$e = new Exception; var_dump($e->debug()); 0.0%
$e = new Exception; var_dump($e->getTraceAsString()); 95.0%
$e = new Exception; var_dump($e->backtrace()); 4.0%
$e = new Exception; var_dump($e->getString()); 0.0%
which of the following will read an object into an array variable?
$array_variable = get_object_vars($object); 62.0%
$array_variable = (array)$object; 37.0%
$array_variable = array $object; 0.0%
$array_variable = get_object_vars $object; 0.0%
which of the following will start a session?
session(start); 0.0%
session(); 0.0%
session_start(); 100.0%
login_sesion(); 0.0%
which of the following will store order number (34) in an 'ordercookie'?
setcookie("OrderCookie",34); 100.0%
makeCookie("OrderCookie",34); 0.0%
Cookie("OrderCookie",34); 0.0%
OrderCookie(34); 0.0%
which one of the following is not an encryption method in php?
crypt() 0.0%
md5() 0.0%
sha1() 2.0%
bcrypt() 97.0%
given 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);
what is the output of the following code?
<?php
echo 0x500;
?>
500
0x500
0500
1280
320
which function will suitably replace 'x' if the size of a file needs to be checked? $size=x(filename);
filesize
size
sizeofFile
getSize
which of the following is the correct way to check if a session has already been started?
if ($_SERVER["session_id"]) echo 'session started';
if (session_id()) echo 'session started';
if ($_SESSION["session_id"]) echo 'session started';
if ($GLOBALS["session_id"]) echo 'session started';
which of the following cryptographic functions in php returns the longest hash value?
md5()
sha1()
crc32()
All return the same hash value length.
which of the following is not a valid api?
trigger_print_error()
trigger_error()
debug_backtrace()
debug_print_backtrace()
what is the difference between the float and the double type in php?
Float is 32-bit while double is 64-bit.
Float represents only rational numbers.
Float and double are aliases for the same thing.
None of these.
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);
?>
There is nothing wrong with the code.
The cURL resource $ch has not been created using the curl_init() method.
The $ch variable needs to be initialized as $ch=null;.
The code will cause a parse error.
which of the the following are php file upload-related functions?
upload_file()
is_uploaded_file()
move_uploaded_file()
None of these
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?
Adding a member variable that gets incremented in the default constructor and decremented in the destructor.
Adding a local variable that gets incremented in each constructor and decremented in the destructor.
Add a static member variable that gets incremented in each constructor and decremented in the destructor.
This cannot be accomplished since the creation of objects is being done dynamically via "new."
what is the correct php command to use to catch any error messages within the code?
set_error('set_error');
set_error_handler('error_handler');
set_handler('set_handler');
set_exception('set_exception');
what will be the output of the following code?
<?php
var_dump (3*4);
?>
int(3*4)
int(12)
3*4
12
None of the above
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)
which of the following methods is used to check if an array is associative or numeric?
is_Assoc().
isAssoc().
is_assoc()
None of the above.
what will be the output of the following code?
<?
$a = 3;
print '$a';
?>
3
$a
Syntax error
None of these
which of these is not a valid simplexml parser method?
simplexml_import_dom()
simplexml_import_sax()
simplexml_load_file()
simplexml_load_string()
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?
Line 8 and 9
Line 10
Line 9 and 10
All the three lines 8,9, and 10 should be left as it is.
what is the meaning of the system message, "allowed memory size of <number> bytes exhausted"?
The available RAM memory is exhausted.
The available disk memory is exhausted.
This occurs randomly due to parsing errors.
The maximum memory allocated in php.ini is exhausted.
should assert() be used to check user input?
Yes
No
which of the following functions is not used in debugging?
var_dump()
fprintf()
print_r()
var_export()
what will be the output of the following code?
<?
$foo = 5 + "10 things";
print $foo;
?>
510 things
5 10 things
15 things
15
None of these
which of the following environment variables is used to fetch the ip address of the user in a php application?
$IP_ADDR
$REMOTE_ADDR_USER
$REMOTE_ADDR
$IP_ADDR_USER
which of the following is true about posting data using curl in php?
Data can be posted using only the POST method.
Data can be posted using only the GET method.
Data can be posted using both GET and POST methods.
Data cannot be posted using cURL.
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?
TRUE
FALSE
NULL
__FILE__
CONSTANT
what is the output of the following code?
<?php
function abc()
{
return __function__;
}
function xyz()
{
return abc();
}
echo xyz();
?>
abc
__FUNCTION__
xyz
<empty output>
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
what is the difference between die() and exit() in php?
die() is an alias for exit().
exit() is a function, die() is a language construct and cannot be called using variable functions.
die() accepts a string as its optional parameter which is printed before the application terminates; exit() accepts an integer as its optional parameter which is passed to the operating system as the exit code.
die() terminates the script immediately, exit() calls shutdown functions and object destructors first.
which of the following is not a valid dom method in php?
loadXMLFile()
loadXML()
loadHTMLFile()
loadHTML()
what will be the output of the following code?
<?php
$str="hello";
$test="lo";
echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;
?>
FALSE
Syntax error
0
1
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>";
?>
Array ( [0] => foo [1] => bar [2] => baz )
foo
bar
baz
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");
what is the best way to load a file that contains necessary functions and classes?
include($filename);
require($filename);
include_once($filename);
require_once($filename);
what will be the output of the following code?
<?php
echo 30 * 5 . 7;
?>
150 . 7
1507
150.7
Integers can't be concatenated.
An error will be thrown.
which of the following is false about curl?
cURL can be used to send plain text data to a remote server.
cURL can be used to send both text as well as files using a single request.
cURL can be used to send files to a remote server.
Files cannot be sent using cURL.
what is the output of the following code?
<?php
$array = array("1","2","3","4");
$variable = end(array_keys($array));
echo $variable;
?>
1
2
3
4
which of the following are not considered boolean false?
FALSE
0
"0"
"FALSE"
1
NULL
what is the fastest way to insert an item $item into the specified position $position of the array $array?
array_insert()
array_splice()
array_merge() and array_slice()
PHP does not have any built-in function that can do this: the source array will have to be copied, and $item inserted in to the required position: $n = 0; foreach ($array as $key => $val) { if ($n == $position) { $target[] = $item; } ++$n; $target[$key] = $val; }
what will be the output of the following code?
<?
$a = (1 << 0);
$b = (1 << 1);
echo ($b | $a) << 2 ;
?>
1
2
3
4
8
12
Syntax error
with regards to the "static" keyword in php, which of the following statements is false?
The $this variable can be used inside any static method.
Static properties may only be initialized using a 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 the class.
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();
Nothing will be printed on-screen.
Foo
Syntax error on line $this->name=$name
Fatal error on line $this->name=$name
which of the following printing construct/function accepts multiple parameters?
echo
print
printf
All of these
what will be the output of the following code? $var = 10; function fn() { $var = 20; return $var; } fn(); echo $var;
10
20
Undefined Variable
Syntax Error
which of the following is not a valid php.ini parameter with respect to file uploading?
upload_max_filesize
allow_url_fopen
upload_tmp_dir
post_max_size
which of the following is true regarding the str_replace() function in php?
It requires a minimum of 2 parameters.
The first argument is the string or array being searched and replaced.
The second argument is the the replacement value that replaces found search values.
It will replace only the first matched string.
which of the following is not a valid xdebug configuration setting?
xdebug.var_display_max_depth
xdebug.var_display_max_children
xdebug.var_display_max_data
xdebug.trace
what is "empty()"?
A function
A language construct
A variable
A reference
None of these
which of the following statements is incorrect?
In a try catch block, the catch block should only appear after the try block.
A try block can have more than one catch block.
A try block can have only one catch block.
When an exception occurs in a try block, control goes to the catch block or the following finally block.
which of the following is not related to debugging in php?
watch
PDO
breakpoints
call stack
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;
?>
1
3
5
12
27
32
Syntax error
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);
?>
Array ( [x] => 9 [y] => 3 [z] => -7 )
Array ( [x] => 3 [y] => 2 [z] => 5 )
Array ( [x] => 12 [y] => 5 [z] => -2 )
Error
None of the above
which of the following will not return an array containing all normal latin alphabet characters (a-z)?
range('A', 'Z');
range('a', 'z');
range(chr(65),chr(90))
range(65,90)
which of these is not a valid php xml api?
libxml_clear_errors()
libXMLError()
libxml_get_errors()
libxml_use_internal_errors()
which line would move the internal pointer to the end of an array?
last($array)
end($array)
finish($array)
boundary($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
$date1 = new DateTime("2007-03-24"); $date2 = new DateTime("2009-06-26"); $interval = $date1->diff($date2); echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";
$date1 = new DateTime("2007-03-24"); $date2 = new DateTime("2009-06-26"); $interval = $date2->diff($date1); echo "difference " . $interval->days . " days ";
$date1 = "2008-11-01 22:45:00"; $date2 = "2009-12-04 13:44:01"; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); $hours = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); $minuts = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); $seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60)); printf("%d years, %d months, %d days, %d hours, %d minuts\n, %d seconds\n", $years, $months, $days, $hours, $minuts, $seconds);
Use CodeIgniter timespan() function
what is the difference between $_server['http_host'] and $_server['server_name']?
There is no difference - both always refer to the same thing.
$_SERVER['SERVER_NAME'] is extracted from the HTTP host header. $_SERVER['HTTP_HOST'] is specified in the web server's configuration file and may be the name of the virtual host.
$_SERVER['HTTP_HOST'] is extracted from the HTTP host header. $_SERVER['SERVER_NAME'] is specified in the web server's configuration file and may be the name of the virtual host.
$_SERVER['HTTP_HOST'] is only available when PHP runs as an Apache module. $_SERVER['SERVER_NAME'] is always available, even if PHP runs as a CGI/FastCGI or CLI process, in which case SERVER_NAME is the host name of the server PHP runs on.
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);
?>
This is a testing module
This is a $var
The code will not work, and will give syntax error.
what is the difference between $a == $b and $a === $b in php?
There is no difference.
'==' checks whether $a and $b have the same string representation, '===' checks whether the values are of the same type and $a is equal to $b.
'==' checks whether $a and $b have the same string representation, '===' checks whether $a and $b are equal after type juggling.
'==' checks whether $a and $b are equal after type juggling, '===' checks whether $a and $b are equal and are of the same type.
when comparing two arrays, what is the difference between "==" and "==="?
"==" compares keys while "===" compares keys and values.
"===" also compares the order and types of the objects.
"===" compares the array references.
They are identical.
None of these.
which of the following variables are supported by the 'str_replace()' function?
Integer
String
Boolean
Array
which of the following is not a valid curl parameter in php?
CURLOPT_RETURNTRANSFER
CURLOPT_GET
CURLOPT_POST
CURLOPT_POSTFIELDS
which of the following is the right mime to use as a content type for json data?
text/x-json
text/javascript
application/json
application/x-javascript
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>";
}
}
?>
b a b
b a a
b b a
b b b
which of the following is not a valid php parser tag?
<script>
<?p
<%
<?php
what is the output of the following code? echo '1'.print(2) + 3;
123
321
511
155
432
which statement will return true?
is_numeric ("200")
is_numeric ("20,0")
is_numeric ("$200")
is_numeric (".25e4")
None
within the phpdoc standard, what is the correct way of "doc commenting" the code?
/** * Comments */ $x = $y + $z;
// Comments $x = $y + $z;
$x = $y + $z; /** * Comments */
$x = $y + $z; // Comments
which of the following statements is incorrect, with regards to inheritance in php?
A class can only have a single parent, i.e. it cannot extend more than one class.
A class can both extend another class as well as implement an interface.
A class can implement more than one interface.
A class can extend more than one class.
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?
function DisplayArray($array) { foreach ($array as $value) { if (array_valid($value)) { DisplayArray($value); } else { echo $value . " "; } } } DisplayArray($array);
function DisplayArray($array) { for ($array as $value) { if (valid_array($value)) { DisplayArray($value); } else { echo $value . " "; } } } DisplayArray($array);
function DisplayArray($array) { for ($array as $value) { if (is_array($value)) { DisplayArray($value); } else { echo $value . " "; } } } DisplayArray($array);
function DisplayArray($array) { foreach ($array as $value) { if (is_array($value)) { DisplayArray($value); } else { echo $value . " "; } } } DisplayArray($array);
what is meant by synchronous server calls within php's curl features?
Performing server calls simultaneously.
Performing server calls within batches.
Performing server calls one after each other.
Performing server calls in parallel.
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;
?>
20 10 10 20
10 10 10 10
20 10 10 10
20 10 20 20
which of the following code snippets has the most appropriate headers to force the browser to download a csv file?
header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0");
header('Content-Type: application/download'); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0");
header('Content-Type: application/csv'); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0");
header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0");
is the ||= operator present in php?
yes
no
which of the following features are supported in php5?
Multiple Inheritance
Embedded Database with SQLite
Exceptions and Iterators
Interoperable XML Tools
which of the following is correct with regard to echo and print?
Echo is a construct and print is a function.
Echo is a function and print is a construct.
Both are functions.
Both are constructs.
which of the following will return the extension of a file name?
pathinfo($filepath,PATHINFO_DIRNAME).
pathinfo($filepath,PATHINFO_BASENAME).
pathinfo($filepath,PATHINFO_EXTENSION).
pathinfo($filepath,PATHINFO_FILENAME).
which of the following functions is not related to garbage collection in php?
gc_collect_cycles()
gc_cycles()
gc_disable()
gc_enable()
what will be the output of the following code?
<?php
</script>
?>
Parse Error
Fatal Error
</script>
?>
which of the following is the best way to get the index(es) of the highest value(s) in an array?
$newarr=arsort($arr); $max_key=array_shift(array_keys($new_arr));
function max_key($array) { foreach ($array as $key => $val) { if ($val == max($array)) return $key; } }
$maxs = array_keys($array, max($array))
function array_max_key($array) { $max_key = -1; $max_val = -1; foreach ($array as $key => $value) { if ($value > $max_val) { $max_key = $key; $max_val = $value; } } return $max_key; }
what will be the output of the following code?
<?php
print null == null;
?>
1
0