Elance PHP5 Test Answers 2015
·
How would you start a session
session
session_start
session(start)
begin_session
Which of the following is NOT supported in
PHP5?
Magic Methods
Multiple Inheritance
Type Hinting
Object Cloning
Reflection
What is the name of the function to check that
the variable type is an object?
isObject
(none of these)
is_object
TypeOject
$x = 10.88; echo (int) $x;
11
1
10
0
What is the correct way to include the file
"time.inc" ?
<?php include file="time.inc"; ?>
<?php include "time.inc"; ?>
<?php include:"time.inc"; ?>
<!-- include file="time.inc" -->
How can I identify the server IP address in
PHP?
$_SERVER['SERVER_ADDR'];
$_ADDRESS['server_ip'];
server_addr();
server_id();
The ____ operator is used to test if two
values are identical in every way.
=
==
instanceof
===
!==
What is the correct way to open the file
"time.txt" as readable?
fopen("time.txt","r");
open("time.txt");
fopen("time.txt","w+");
open("time.txt","read");
The function used to iterate over array and
object.
foreach
while
for
dowhile
Include files must have the file extension
".inc"
No
Yes
What Does OOM mean?
Object Original Miscleneaous
Object Orientaton Mechnism
Object Over Masterclass
Original Overlap Model
Object Oriented Model
How do you kill or destroy a session?
reset_session()
kill_session()
session_kill()
session_destroy();
destroy_session()
Which of the following function is used to
check type of array
array_valid
isArray
valid_array
is_array
Which function can be used to rename files?
fwrite()
copy()
rename()
fputs()
die()
Does PHP5 support Exceptions?
Yes
No
How to open file in read/write mode?
$handle =
fcopen("http://www.example.com/", "r+");
$handle =
fopen("http://www.example.com/", "r");
$handle = fileopen("http://www.example.com/",
"r+");
$handle =
fopen("http://www.example.com/", "r+");
$handle =
fcopen("http://www.example.com/", "r");
What operator is used to test if two values
are identical in every way
==
instanceof
===
=
!==
Which of the following function is used to
display the properties of variable?
explain
none of the above
define
var_dump
Which of the lines below will output the
following string: "PHP is "super easy" to use!"
echo (\"PHP is 'super easy' to use!\");
echo "PHP is \"super easy\" to
use!";
echo ("PHP is "super easy" to
use!");
echo "PHP is "super easy" to
use!";
Which function would you use to append one or
more elements to the end of the array?
array_shift()
array_unshift()
array_pop()
array_push()
Which of the following responsible for change
the current directory?
opendir()
closedir()
chdir()
dir()
rewinddir()
What is PEAR in PHP?
There is no PEAR in PHP.
PHP Extended Applications aRchive
PHP Extension and Application Repository
Which of the following is a php resource?
(all of these)
File
Database link
ODBC Link
What is the meaning of the below code? $file =
'sample.txt'; $current = file_get_contents($file); $current .= "Additional
Info"; file_put_contents($file, $current);
None of these
A certain string of value 'Additional Info' is
added to the end of the file named sample.txt.
A certain string of value 'Additional Info' is
over-written in the file named sample.txt.
A fatal error would be caught by
E_ERROR
E_ALERT
E_NOTICE
E_WARNING
ERROR
How can you delete a file using a php
function?
remove
drop
delete
unlink
deletefile
(8 < 1 || 4 >= 4 ) will return
True
False
If regular expressions must be used, in
general which type of regular expression functions available to PHP is
preferred for performance reasons?
preg_* regular expression functions
strtok() using regular expressions
ereg* regular expression functions
strregex* regular expression functions
What function in PHP allows you to find the
position of the first occurrence of a substring?
strpos()
str_repeat()
strtok()
strripos()
substr()
Which array function checks if the specified
key exists in the array?
isset()
array_search()
array_key_exists()
is_array()
True or false? One can include (”abc.PHP”) two
times in a PHP page “makeit.PHP”.
True
False
Which of the following is not related to file
fappend
fopen
fgets
fclose
fwrite
What is the best way to URL encode a string?
encode_url( $str )
urldecode( $str )
encodeurl( $str )
urlencode( $str )
urlcode( $str )
$a = &$b; $b = 'Mary?'; print $a;
Fatal error
Empty output
Notice
Mary?
Warning
Which of the following is not a boolean false
False
false
1
(none of these)
PDO::beginTransaction() turns off autocommit
mode.
False
True
How do you make PHP use a class file without
having to require or include it manually?
Define __autoload($class) magic function
There's no way to do it
Use set_class_handler($class_handler) function
Set default_lib_path variable in php.ini
Define $_MAP superglobal
function foobar( ) { $a = func_get_args( );
return $a[2]; } print foobar('a',1,'b',2); What would the output be?
a2
a
2
b
1
In mail($param1, $param2, $param3, $param4),
the $param2 contains:
The subject
The header
The message
The recipient
Which of the following responsible for
generates the backtrace
user_error()
error_get_last()
debug_print_backtrace()
debug_backtrace()
trigger_error()
( (4 >= 4 && 8 < 1) || (44 == 33
|| 5 > 3) ) will return
TRUE
FALSE
What visibility level will this class property
get in PHP5? var $cool = true;
public
protected
var keyword is no longer valid in PHP5
private
Which of the following functions split the
string and return the array?
str_split()
strsplit()
split_str()
splitstr()
stringsplit()
Which of the following is ternary operator
=
+=
:?
?:
&
What is the difference between $message and
$$message?
Error
Memory pointer
Classic example of PHP’s variable variables
What is the primary difference between a
method declared as static and a normal method?
Static methods cannot be called from within class
instances
There is no functional difference between a static
and non-static method
Static methods don't have access to the self
keyword
Static methods do not provide a reference to $this
How do you connect mysql with the use of PHP5
new functions?
(both answers are correct)
$user = 'user'; $pass = 'pass'; $connection = new
PDO('mysql:host=localhost;dbname=test', $user, $pass);
$connection = new mysqli('localhost', 'user',
'pass', 'test');
True or false? PHP provides the goto in the
latest version.
False
True
Which of these functions will not result in a
runtime error if the file requested does not exist or can't be opened?
getFile()
require()
include()
nowarn()
What is the name of default class for all
classes
CLASS
NSObject
Object
__CLASS__
stdClass
Which of the following functions would one use
to get the number of parameters passed?
func_get_args
arg_num
func_num_args
$a = array("pomme",
"banane"); $b = array(1 => "banane", "0" =>
"pomme"); var_dump($a == $b); What does-it print ?
FALSE
TRUE
Which PCRE regular expression will match the
string
/[hp1-5]*\-.?/
/[hp][1-5]*\-.*/
/^[hp1-5]*\-.*/i
Which of the following variables is not
related to file upload?
max_input_time
post_max_size
max_file_size
max_execution_size
What is not a PHP type?
callable
resource
boolean
NULL
complex
What prefix prevents child classes from
overriding a method
private
final
protected static
private static
What is wrong with the following code?
<?php function duplicate($obj) { $newObj = $obj; return $newObj; } $a = new
MyClass(); $a_copy = duplicate($a); $a->setValue(10);
$a_copy->setValue(20); ?>
You must use return &$newObj instead
duplicate() must return a reference
You must use the clone operator to make a copy of
an object
There is nothing wrong with this code
$text = 'He went to the school.'; echo
strpbrk($text, 'w'); In the above code, what is the output?
all of these
went to the school.
None of these
true
3
$a = 'Hello'; echo (int)!!$a;
TRUE
0
FALSE
1
Hello
To ensure that a given object has a particular
set of methods, you must provide a method list in the form of an ________ and
then attach it as part of your class using the ________ keyword.
instance, implements
interface, implements
access-list, instance
interface, extends
array, interface
Which of the following functions set options
in curl script?
curl_setopt()
curl_set_opt()
curl_opt()
curl_option()
curl_set_option()
Which function will list files and directories
inside the specified path?
fscan()
readdir()
scandir()
opendir()
fopen()
Which of the following functions allows you to
store session data in a database?
session_set_save_handler();
You cannot store session data in a database.
mysql_query();
session_start();
Given: $email = ‘bob@example.com’; which code
block will output example.com?
print strstr($email, ‘@’);
print substr($email, strrpos($email, ‘@’));
print substr($email, strpos($email, ‘@’) + 1);
print substr($email, -1 * strrpos($email, ‘@’));
Which subversion of PHP5 adds short array
syntax?
3
5
2
4
What will be the output of the following code:
<?php class A {} class B {} class C extends B {} class D { function sayHello
(A $argument) { echo '$argument is an instance of A'; } function sayHello (B
$argument) { echo '$argument is an instance of B'; } } $d = new D(); $c = new
C(); $d->sayHello($c);
PHP Fatal error
$argument is an instance of B
$argument is an instance of A
Call to undefined method D::sayHello()
What is the best way to iterate and modify
every element of an array using PHP 5?
for($i = 0; $i < count($array); $i++) { /* ...
*/ }
foreach($array as $key => $val) { /* ... */ }
You cannot modify an array during iteration
foreach($array as $key => &$val) { /* ... */
}
while(list($key, $val) = each($array)) { /* ... */}
How to check if a directory exists?
is_exists($name);
dir_exists($name);
is_dir_exists($name);
file_exists($name);
What is output of the following code? $arr =
"a"; $arr[0]="b"; echo $arr; echo $arr[0];
bb
ab
Fatal Error.
PHP Warning.
aa
$sweet = array('1' => 'apple', '2' =>
'banana'); $fruits = array('delicious' => $sweet, 'sweet' =>
'strawberry'); function myprint($item, $key) { echo "$key is
$item\n"; } array_walk_recursive($fruits, 'myprint'); In above code, what
is the output?
[delicious is apple] [delicous is banana] [sweet is
strawberry]
[apple is delicious] [banana is delicious]
[strawberry is sweet]
[1 is apple] [2 is banana] [sweet is strawberry]
Which of the following is a correct
declaration?
Static $var = new object;
Static $var = sqrt(25);
Static $var = array(10,'str',3);
Static $var = 1+(5*13);
How do you get header information from a URL?
get_headers()
None of these
get_header()
get_header_info()
What result? $a = "1"; $a[$a] =
"2"; echo $a;
1
error
3
2
12
The contents of an image file are stored in
memory as $imString, but the original file is not available. Of the following,
which uses the least amount of code and is a valid method of retrieving the
dimensions of $imString?
$fn = tempnam('/dir', 'foobar');
file_put_contents($fn, $imString); return getimagesize($fn);
return getimagesizefromstring($imString);
None of the above are valid PHP code
return strlen($imString);
$im = imagecreatefromstring($imString); return
array(imagesx($im), imagesy($im));
What is the difference between idate and date
function?
idate function always returns a formatted date
string, but date function returns a formatted date string or FALSE.
idate function has more diverse expressions than
date function.
idate function always returns an integer, but date
function returns formatted date string or FALSE.
None of these
All of these
Which of the following functions compare the
substrings of the parameters?
substr_comp()
substr_compare()
compare_substr()
None of these
comp_substr()
$a = array("pomme",
"banane"); $b = array(1 => "banane", "0" =>
"pomme"); var_dump($a === $b); What does-it print ?
FALSE
TRUE
____ will walk through the entire array
regardless of pointer position.
array_loop()
foreach()
array_map()
array_walk()
What is the output in following codes?
<?php $array1 = array("a" => "green",
"red", "blue"); $array2 = array("b" =>
"green", "yellow", "red"); $result = array_intersect($array1,
$array2); print_r($result); ?>
Array ( [0] => green [1] => red )
Array ( [a] => green [b] => red )
Array ( [a] => green [2] => red )
Array ( [a] => green [1] => red )
Array ( [a] => green [0] => red )
What this code will outputs? class Animal {
public $name = 'dog'; } $a = new Animal(); $b = clone $a; $c = $a; $a->name
= 'cat'; $b->name = 'bear'; $c->name = 'parrot'; echo $a->name . ', '
. $b->name . ', ' . $c->name;
cat, bear, cat
parrot, bear, parrot
dog, dog, dog
cat, bear, parrot
What will be output of this code. function
test(&$var) { $var=$var-1; return $var; } $returnVar = test(50); echo
$returnVar. " is answer.";
49 is answer.
50 is answer.
51 is answer.
Error message
Which variable type can NOT be used as a type
hint?
resource
array
any class name
callable
Which of following functions get a list of
response headers sent (or ready to send)?
None of these
headers_list()
get_header_list()
header_list()
What is the function to report errors from
mysqli functions or queries?
mysql_generate_report();
mysqli_report_error();
mysqlireport();
mysqli_report();
mysql_sql_exception
What is the output of the following code? echo
new stdClass == new stdClass, '-', new stdClass !== new stdClass;
0-0
1-1
0-1
1-0
Which of the following functions is a relative
ftp function new to PHP5?
ftp_chdir()
ftp_chmod()
ftp_alloc()
ftp_mkdir()
ftp_read_write_alloc()
What will following code outputs? function
add($a) { return $a++; } echo add(5);
E_WARNING
E_NOTICE
6
4
5
What will be the output of the next code? :
$someString = 1.2e3; var_dump(strlen($someString));
int 5
int 1200
int 4
How should you filter variables before passing
to header()?
urlencode()
PHP's doing this itself nowadays
strtr($var, "\r\n", ' ')
htmlspecialchars()
What is the output of this code snippet? $i =
5; print $i++ + ++$i;
11
10
13
12
The number of parameters in setCookie function
5
7
4
2
3
Which function would you use to prepend one or
more elements to the beginning of an array?
array_unshift()
array_pop()
array_shift()
array_push()
What will be the result of the following code
? $a = 0 or 1; $b = 0 || 1; echo "$a, $b";
1, 1
0, 1
1, 0
0, 0
Key casts in arrays. What is the resulting
array $a = array( 1 => "John", "1" =>
"Doe", 1.5 => "Jane", true => "Smith", );
Array ( [1] => "John", ["1"]
=> "Doe", [1.5] => "Jane", [true] => Smith )
Array ( [1] => "John", [1.5] =>
"Jane", [true] => Smith )
Array ( [1] => John )
Array ( [1] => "John", [1.5] =>
"Jane", )
Array ( [1] => Smith )
Which is not a magic method?
__wakeup()
__sleep ()
__debugInfo()
__set_state()
__invokeStatic()
What will be the array $b after executing this
code? $a = array(1, 3, 5); $b = array(2, 4, 6); $b += $a;
$b = array(3, 7, 11)
$b = array(2, 4, 6)
$b = array(2, 4, 6, 1, 3, 5)
$b = array(1, 2, 3, 4, 5, 6)
PHP Fatal Error
Which of following functions compute the
intersection of arrays with additional index check and are defined newly in
PHP5?
array_intersect_assoc(); array_intersect_uassoc();
array_wintersect_assoc(); array_wintersect_uassoc();
array_intersect_new_assoc();
array_intersect_new_uassoc();
array_uintersect_assoc();
array_uintersect_uassoc();
array_nintersect_assoc();
array_nintersect_uassoc();
When passing an undefined variable to a
function by reference, e.g. function test(&$var) { /* ... */ } unset($x);
test($x); What is the error message?
PHP Fatal error: Undefined variable: x
No error message, the script will be aborted.
No error message, the variable will be created.
PHP Notice: Undefined variable: x
For PHP version <= 5.3, how can we activate
error reporting for all levels?
error_reporting(E_ERROR);
error_reporting(0);
error_reporting(E_ALL);
error_reporting(-1);
What does php_strip_whitespace function
return?
Returns the PHP source code in filename with PHP
comments and whitespace removed.
Returns the string with whitespace removed
None of these
Returns the PHP source code in filename with
whitespace removed.
Returns the string with comments and whitespace
removed.
Subscribe to:
Posts (Atom)