Elance PHP Test Answers 2015 ( Part - 2 )
·
15 minutes
Never
Until the browser is closed
Depends on the client browser
30 minutes
class A{} class_alias( 'A', 'B' );
var_dump(new B); outputs ...
NULL
bool(false)
object(A)#1 (0) { }
object(B)#1 (0) { }
What does the following PHP code do?
preg_filter($pattern, $replace, $subject)
Performs a regular expression search and replace
None of these
Performs a regular expression search and replace
using a callback
Returns array entries that match the pattern
Which function can be used to simplify
searches in databases where you know the pronunciation but not the spelling
explode
strtolower
soundex
parse_str
preg_search
What is the output of the following code?
$one='two'; $two='one'; echo $$$one;
does not output anything
generates an error
onetwo
two
one
PHP's echo and print functions are not exactly
alike. Which will accept multiple parameters and concatenate them in its
"without parentheses" form?
print
neither echo nor print
echo
both echo and print
Which of the following statements is NOT true
for PHP constants?
Their value cannot change for the duration of the
script.
They are case sensitive.
The scope of a constant is local.
A valid constant name starts with a letter or an
underscore.
Which of those is not magic method?
__toString
__sleep
__clone
__toInt
__callStatic
How do single quotes interpret strings in PHP?
None of these
literally
literally except for variables which are expanded
escape sequences are interpreted
When passing an object to json_encode(), the
default behavior can be modified by:
Defining the __toJson() function.
Implementing the JsonSerializable interface.
It's not possible to change the default behavior.
Defining the __toArray() function.
Which statement opens a file for writing, to
append data at the end of its content ?
fopen("myFile", "w")
fopen("myFile", "wa")
fopen("myFile", "r+")
fopen("myFile", "a")
what will be the output: $array1 =
array("a" => "green", "b" =>
"brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow",
"red"); $result = array_diff_assoc($array1, $array2);
print_r($result);
Array ( [b] => brown [c] => blue [0] =>
red )
Array ( [c] => brown [b] => blue [0] =>
red )
Array ( [b] => brown [c] => blue [d] =>
red )
Array ( [b] => brown [c] => blue [a] =>
red )
What will the following code output:
array_map("print_r", array( 'a', 'b' ) );
ab
Nothing
Array{ [0] => 'a', [1] => 'b' }
a
What does the use of the final keyword in a
method declaration prevent?
All of these
Specific properties within a class from being
modified.
Child classes from overriding the method.
Objects from being modified.
$a = array('a' => 0, 'b' => 0, 'c' =>
1, 'd' => 2); $b = array_flip($a); var_dump($b); What does the 'var_dump'
function show ?
array(3) { [0]=> string(1) "a"
[1]=> string(1) "b" [2]=> string(1) "c" [3]=>
string(1) "d" }
array(4) { 'd' => int 2 'c' => int 1 'b'
=> int 0 'a' => int 0}
array(3) { [0]=> string(1) "b"
[1]=> string(1) "c" [2]=> string(1) "d" }
What does the glob() function return?
All system global variables
An array of all global variables into the user
defined function
An array of filenames / directories matching a
specified pattern
Given an array of images, $images =
array("img12.png", "img10.png", "img2.png",
"img1.png"), which function will sort $images into
("img1.png", "img2.png", "img10.png",
"img12.png")?
arsort($images);
natsort($images);
usort($images);
ksort($images);
asort($images);
Which PHP function would you use to get
information about the current session cookie?
session_set_cookie_params()
set_cookie()
get_cookie()
session_get_cookie_params()
What is the correct way to call an anonymous
function?
callback($functionName, $var);
call_function($var);
$func($var);
anonymous($var);
Choose the correct output of: <?php $email
= 'admin@domain.tld'; echo strstr($email, '@'); ?>
admin@domain.tld
@domain.tld
domain.tld
admin
Which mode parameter should be used with the
fopen() function to open a file and point to the end for writing only?
c+
w
a+
a
What is the result of calling json_encode() on
an empty array?
[] - An empty JavaScript array
{} - An empty JavaScript object
undefined
'' - An empty JavaScript string
Which type of error can NOT be caught with a
custom error handler?
E_USER_ERROR
E_RECOVERABLE_ERROR
E_WARNING
E_NOTICE
E_ERROR
Which of the following code snippets will
split a string into an array with 3 elements?
$array = str_split("a b c", 2);
All of them
$array = split(" ", "a b c");
$array = explode(" ", "a b c");
$array = sscanf("a b c", "%s %s
%s");
What will be the output for the following
code? $values = array(0, NULL, FALSE); foreach($values as $key => $value) {
echo isset($values[$key]) ? "TRUE " : "FALSE "; }
TRUE FALSE FALSE
TRUE FALSE TRUE
fatal error when using isset on an array
TRUE TRUE TRUE
FALSE FALSE FALSE
What are Traits in PHP?
Traits allow multiple inheritance for classes.
Traits allow code reuse without direct inheritance.
Traits are class interfaces.
Traits are all of these things.
is_a( $a, $b ) will:
it is not a built-in php function
check if $a is of class "$b" or has this
class as one of its parents
Check if $a is of type "$b"
Which PHP function will return a file's last
access time?
fileaccesstime()
file_access_time()
filectime()
fileatime()
What is the value of $a in the following:
<?php $a = array_pad( array( 0 ), 2, 1 ); ?>
array( 0, 2 )
array( 2 )
array( 0, 1 )
NULL
Sleep(3000); will sleep the page for?
300 seconds
3000 seconds
30 seconds
3 seconds
What is the output of the following code?
<?php echo str_pad("abc", 6, "7"); ?>
abc777
abcde67
abcde6666666
abcde777777
777abc
use keyword is used only for namespace
false
true
What is the result of the following code :
<?php echo (strpos('abcdef', 'a')) ? : -1; ?>
true
0
Syntax error
-1
1
What is the result of the following code ?
<?php $a = 1; echo $a++; $a *= 2; echo ++$a; ?>
24
11
25
14
15
What will be the final structure of the
following array? $animals = array( 'dog', 'cat', true => 'lion' );
array( 0 => 'dog', 1 => 'cat', true =>
'lion' )
Syntax Error will be thrown, as all keys must be of
the same type
array( 0 => 'dog', 1 => 'lion' ) - boolean
true will be changed to integer 1
Syntax Error will be thrown, as array keys can't be
boolean values
array( 0 => 'dog', 1 => 'cat' ) - element
with boolean key will be ignored
Which of the following functions inserts one
or more elements to the beginning of an array?
array_merge()
array_walk()
array_unshift()
array_push()
array_shift()
What does this display? <?php $x =
array('a'=>1, 'b'=>2, 'c'=>3); echo key($x);
"a"
array( 0, 1, 2 )
array( 'a', 'b', 'c' )
0
Which function returns an item from the
argument list?
func_get_arg()
None of these
func_num_args()
func_get_args()
<?php $x = 1; echo($x++ + ++$x + $x)*2;
Which will the output be?
12
15
14
16
13
Which of the following superglobals doesn't
contain data from the client?
$_POST
$_COOKIE
$_SESSION
$_SERVER
$_GET
Which function can be used to convert data
into a binary string according to a specified format?
pack()
nex2bin()
encode_hex()
printf()
What does mt_srand( [int $a] ); do?
Subtracts a random integer from the passed argument
and returns the result
Returns a random integer
Returns a random string of the length specified by
the first argument
Initializes a random number generator
This function does not exist
Which of the following protocols is not
supported by PHP streams?
imap
ftp
ssh
bz2
Which elements can be encapsulated by
namespaces?
Only classes
Classes, functions and constants
Classes, functions, constants and variables
How do you call a static method defined by the
called class from a parent class?
None of these. It is not supported in the language.
Parent classes cannot access static methods defined by children.
parent::func();
static::someFunc();
$obj = new __CLASS__; $obj->func();
self::someFunc();
True or False? Within the eval() function,
code must be opened and closed with PHP tags, i.e. <?php echo 'hi'; ?>
False, but you can still exit and enter PHP mode
using tags
True, you MUST use PHP tags as everywhere
False. You can't use PHP tags with eval()
An object can be counted with count() and
sizeof() if it:
None of the above
Has a public __count() method
Was cast to an object from an array
Implements ArrayAccess
Which function would you use to obtain the
ASCII value of a character?
chr( );
ord( );
val( );
asc( );
Which of the following network transports
doesn’t PHP support?
tcp
pdc
unix
udg
When adding ('+' function) two variables of
type integer and type string, what type is the resulting value?
Integer
Depends on the content of the string
String
What is the time complexity of a call to
array_key_exists()?
O(N^2)
O(N * log N)
O(1)
O(log N)
O(N)
What function allows you to print a backtrace?
debug_backtrace_print
debug_print_backtrace
backtrace_print
backtrace
print_backtrace
Which of the following is not a valid PHP
variable type conversion?
array to object
string to object
reference to array
object to reference
Which function is used to read an entire file
into an array ?
file_to_array
fwrite
file_get_contents
file
fgets
Which of the following is the predefined class
in PHP?
__PHP_Incomplete_Class
Special_Iterator
None of them
ErrorFault
PHP_RpcClient
What data types cannot be used with PHP5 Type Hinting?
Strings, Interface
Integers, Array
Objects, Array
Integer, Strings
What does this code do? namespace Hello\World;
It creates two namespaces : "Hello" and
"Hello\World"
It creates two namespaces : "Hello\World"
and "World"
It creates one namespace : "World"
It creates two namespaces : "Hello" and
"World"
It creates one namespace : "Hello\World"
What is the name of variable storage container
in php
Storage
zval
Memcache
Memrise
var
$a = array('z','x','y'); $b = sort($a); The
value of $b is?
array('x','y','z')
False
array('z','y','x')
True
Which function returns the size of a specified
file on the FTP server?
ftp_file_size()
get_ftp_size()
ftp_amount()
ftp_size()
Is it possible to typehint function arguments
using native types (String, Bool, Array, Int, Float, Binary...)?
Yes, using all types
Only Array is supported
All types except String
Is there a function to listen on E_ERROR
(fatal) errors?
It's not possible
set_error_handler()
register_shutdown_function()
Which PHP extension allows you to simplify
converting between different calendar formats?
date/time
calendar
All of these
Julian
What is the output of the following code:
<?php $x = 0x22; echo <<<'END' $x END; ?>
18
$x
0x22
Syntax error
34
Which PHP function reads entire file into an
array?
file
fopen
readfile
fgets
file_get_contents
Subscribe to:
Posts (Atom)