Elance PHP Test Answers 2015 ( Part - 1 )




Elance PHP Test Answers 2015 ( Part - 2 )


In PHP, variables always start with which symbol?
&
$
!
%
#


Which of the following would be accepted as an argument parameter in the following function: function getEmotion(Emotion $emotion) { ... }
All of these
A class called Emotion
A class called Sad, which implements an Emotion interface
A class called Happy, which extends Emotion


"virtual()" in PHP
makes the final method overrideable again
is equivalent to the keyword "abstract"
marks the method as virtual, so it could be overridden
is an Apache-specific function


Which PHP function checks a month, day, and year number to determine if they form a valid Gregorian date?
check_date()
checkdate()
verify_date()
verifydate()


Which function exchanges all keys with their associated values in an array?
array_flip(array)
array_combine(array)
array_compare(array)
array_reverse(array)


Which PHP functions generate random numbers following algorithms known as Mersenne Twister?
mt() and smt()
mt_alg() and mt_salg()
rand() and srand()
mt_rand() and mt_srand()


What does the return code E_ERROR indicate?
Compile-time parse error
User-generated error message
Fatal run-time error
Run-time notice


Which of the following functions would allow you to convert a string to an array?
st2arr()
expand()
explode()
to_array()
implode()


Which variable name is incorrect?
$first
$1first
None of the above.
$_1FIRST


What is a collection of characters that is treated as one entity called?
Element
Parameters
Function
String


What is output to the screen when executing code: $> php -r 'echo echo "a";'
a
truea
aa
PHP Parse error


How can we increase the execution time of a PHP script from setting php.ini?
By setting max_script_execution_time
By setting max_execution_time
By setting max_script_time
By setting script_execution_time


What type of statements tell your PHP script to execute a section of code only if certain criteria are met?
Class
Function
Exception
Conditional


What is the result of the following code? <?php $hello ="HELLO"; $hello=lcfirst($hello); echo $hello; ?>
hellO
None of these
hello
hELLO
HELLO


Which PHP math function would you use to return the number with the lowest value of two specified numbers?
ceil()
min()
bottom()
max()


PHP requires that instruction statements be terminated with a:
semicolon
underscore
curly brackets
period


Which of these does not represent a single, valid PHP variable
$myVar
$my-Var
$my_Var
$myvar


Which function tests a string for an exact match of the argument?
preg_match()
str()
test()
regex()


How do you inherit the methods from BaseClass in MyClass?
class MyClass parent BaseClass {
class MyClass includes BaseClass {
class MyClass extends BaseClass {
class MyClass inherits BaseClass {
class MyClass using BaseClass {


Which statement returns the number of characters in the string variable $a?
count($a)
strlen($a)
chr($a)
len($a)
sizeof($a)


Which of the following is a string operator?
plus(+)
minus(-)
decrement(--)
dot(.)


Which of the following variables does PHP make automatically available to you?
$_UPLOADED_FILES
$_DIR
$_SERVER


The concatenation operator in PHP is
.
+
->


Which PHP function do you call to begin a PHP session?
start_session();
open_session();
session_start();
session();
session_active();


Which of the following are examples of PHP comments?
/* */
None of these
//
All of these


How is the following statement interpreted in PHP? $i = 1;
$i is being compared to 1
$i is assigned a value of 1
None of these
$i is assigned a value of "one"


Which of the following are PHP comparison operators?
===
All of these
!=
==


Which PHP math function would you use to generate a random integer?
int()
rand()
random()
next()


Which of the following HTML form submission methods is suitable when you need to send large amounts of form data?
Get
Post
Email
Send




How do you define a constant in PHP?

defined("CONSTANT", "Hello world.");

define("CONSTANT", "Hello world.");
eval("CONSTANT", "Hello world.");
constant("CONSTANT", "Hello world.");


Which statement allows you to add new records to a MySQL database table?
All of these
PUT INTO
INSERT INTO
ADD INTO


Which of the following function libraries are supported in PHP?
All of these
JSON
MySQL
GD


Which of the following variables is not a predefined variable?
$_REQUEST
$_GET
$_POST
$_ASK


How do you combine multiple arrays into one single PHP array?
array_pop()
array_merge()
array_compare()
array_shift()


Which of the following PHP language constructs allows you to combine code from one file into another?
require()
All of the these
include()
require_once()


Which PHP function sorts an array?
array_alpha()
combine()
array_walk()
sort()


Which variable is not predefined by PHP?
$_GET
$_FILES
$_POST
$_ASK


An example of a PHP string is:
$a
"test"
&&
10


In PHP, how would you determine if a variable is set?
isset()
unset()
combined()
isinit()


Variables in PHP start with a
dollar sign($)
underscore(_)
ampersand(&)
dot(.)


In PHP, functions using global variables must declare the variables by using
the STATIC keyword.
the LOCAL keyword.
the GLOBAL keyword.


Which variable is used to collect values of a form sent via the HTTP POST method?
$POST
_POST_
$_POST
POST


Choose the statement which produces this output: This is an example.
<?php echo "This is an example."; ?>
<? "This is an example."; ?>
<p="This is an example."; ?>
<script language="php"> print "This is an example.";</script>


Which of the following is a valid PHP function modifier?
private
All of these
public
final


strpos() stands for
straight position.
strap OS.
string position.
string positive.


If the allow_url_fopen configuration setting is enabled, which of the following functions will be able to open remote urls?
All of these
require_once()
require()
include()


One way to output a string in PHP is:
output()
str()
display()
echo()


Which function checks for a specific PHP data type?
is_float()
All of these
is_int()
is_numeric()


What does MVC stand for?
Many Variable Classes
Maximum Visitor Connections
Model View Controller
Model Variable Container


How do you retrieve the value of a variable called "name" which has been passed from a submitted form?
Request.Form;
Request.QueryString;
$_GET["name"];
$_GetParameter[];


Which function will generate random integers?
rad2deg()
search()
rand()
find()


What types of arrays are supported in PHP?
Multi-dimensional
Associative
Numeric
All of these


What's the output? $name = 'John'; echo 'Hi there '.$name;
Hi there
Hi there John
Nothing. There is a syntax error


How do you write "Hello World" in PHP
"Hello World";
echo "Hello World";
document.print("Hello World");
out << "Hello World";


Which is a valid loop method in PHP?
Do
For
All of these
While


PHP variables always begin with
a letter.
a dollar sign($).
underscore(_).
a number.


The PHP language can be used on the following operating systems:
Mac OS X
All of these
Windows NT
Linux


The function mysql_connect( ) takes following parameter(s):
server
username
All of these
password


What are int, float, string and boolean examples of in PHP?
integers
pointers
classes
data types


Which construct includes an external PHP file?
include
require
All of these
require_once


What is the correct way to create a function in PHP?
create myFunction(){ echo "Example function.\n";};
function myFunction(){ echo "Example function.\n";};
createFunction myFunction(){ echo "Example function.\n";};
new_function myFunction(){ echo "Example function.\n";};


What should you do in advance, to get and set session variable
session_start()
session_start_func()
sessionstart_func()
sessionstart()
_session_start()


The logical operator OR is similar to:
!=
&&
!==
||


Which PHP function completely destroys all data relevant to the session?
session_end();
session_destroy();
session_close();
destroy();


Which function would you use to check for data type?
is_int()
is_numeric()
is_float()
All of these


Which function creates a directory on the FTP server?
ftp_makekdir()
ftp_mkdirectory()
ftp_mkdir()
ftp_makedirectory()


Which is a characteristic of the PHP language?
scripting language
open source
All of these
embedded into HTML


CakePHP, Zend, and CodeIgniter are popular _________ used on many PHP servers.
unit testing packages
development frameworks
cacheing tools
image processing libraries
version control software


How do you add a multi-line comment in PHP?
<!-- This is a comment -->
/* This is a comment */
*\ This is a comment \*
<comment> This is a comment </comment>


All variables in PHP start with which symbol?
!
$
@
%


PHP supports which of the following features?
associative arrays
include files
All of these
mathematical functions


Placing ++ in front of variable:
creates a fatal error
will cause a syntax error
preincrements the variable by one
will print as a string


What PHP function calculates the sum of the values in an array?
array_pop()
array_math()
array_sum()
array_add()


Which operator is used to concatenate strings in PHP?
ampersand (&)
plus (+)
logical and (and)
dot (.)


Which function is used to perform a regular expression match in PHP?
match()
preg_match()
combine()
parse()


The statement header('Location: http://www.somesite.com'); will
displays the IP address of somesite.com.
redirects the browser to www.somesite.com.
creates a hyperlink.
displays the header of somesite.com.


Which PHP function opens a file for reading only?
open("c:\\test\\time.txt");
fopen("c:\\test\\time.txt" , "w");
fopenr("c:\\test\\time.txt" , "r");
fopen("c:\\test\\time.txt" , "r");


HTML form input needs to be validated in order to avoid:
SQL Injections.
hacking.
All of these
database intrusions.



What do you need to call in order for your session variables to work?

session_start()
session_begin()
$_SESSION_BEGIN
ob_start()
session()


A string literal in PHP can be specified in the following way(s):
'this is a string'
"this is a string"
All of these
<<<EOT this is a string EOT;


Which of the following variables is expected to contain information about the user's browser?
$_SERVER['HTTP_VARIANT']
$_SERVER['SERVER_NAME']
$_SERVER['PHP_SELF']
$_SERVER['HTTP_USER_AGENT'];


Which of the following returns information passed via HTTP forms?
$_GET
$_POST
All of these
$_REQUEST


Which PHP language construct sends output to a browser window?
return
echo
output
display


Which PHP function would you use to display the value of an array in a readable format?
display()
print()
print_r()
return()


An example of a float in PHP is:
All of these
7E-10
1.2E3
12.678


Which of the following checks if a value exists in an array?
exists_list
exists
PHP does not provide any inbuilt way of doing this.
in_array


In the following PHP script, $arr = array(1,2,3);, 1, 2, and 3 are the array
index
keys
subscript
values


What kind of error causes the termination of the script?
None of them
Fatal Errors
Notices
Warnings


Which PHP function finds the position of the last occurrence of a substring within a string?
pos()
strrpos()
split()
haystack()


$var = (10 % 2 == 0) ? true:false; What is the output of $var?
false
true


Include files must have the file extension ".inc"
True
False


To modify the default PHP settings such as whether to accept the short form open tag (<?), you need to change the
htaccess file.
php.inc file.
php.ini file.
machine.config file.


Which function gives you the current PHP version information?
phpversion()
version()
version_compare()
phpcredits()


Which PHP function returns part of a string?
ctrl alt delete
strpos()
All of these
substr()


Which function can be used to convert 'ff' to 255?
octdec()
bindec()
dechex()
hexdec()


The practice of combining strings and variables into one string is called:
joining
connecting
combination
concatenation


What is meant by nl2br()?
Inserts HTML line breaks (<BR />) before all newlines in a string.
Inserts HTML line breaks (<P />) before all newlines in a string.
Inserts HTML line breaks (<HR />) before all newlines in a string.
Inserts HTML line breaks (<NL/>) before all newlines in a string.


If a string is enclosed in double-quotes, PHP will interpret more escape sequences for special characters such as
\n
\"
\r
All of these


Which of the following is NOT a command for sending output to the standard output?
send
print
printf
echo


Which of the following stores PHP values, such as strings, numbers or arrays?
variables
ID's
attributes
classes


Which PHP function would you use to display information about variables in a simple, readable format?
display()
infp()
dump()
var_dump()


mysqli_num_rows() function is used to:
Get all rows contain numbers.
Count number of columns in MySql Table.
Get all columns with numeric data.
Count number of characters in single row of MySql Query result.
Count number of rows in result of MySql Query.


Which statements start a session and end a session?
begin_session(); end_session();
session_start(); unset_session();
start_session(); session_explode();
session_start(); session_destroy();
start_session(); end_session();


What does the acronym LAMP stand for?
Linux And MySQL PHP
Linux Apache MySQL PHP (or Perl/Python)
Linux Apache Monitoring Program
Linux Application in MySQL PHP


How to call a method from within a class?
$this( my_function() );
public my_function();
$this.my_function();
$this->my_function();
private my_function();


Which construct is typically used for exception handling in PHP?
E_STRICT
try / catch
session();
modify()


In PHP, which statement is used to retrieve browser properties?
$_SERVER['PHP_SELF']
$_SERVER['SERVER_NAME']
$_SERVER['HTTP_USER_AGENT'];
$_SERVER['HTTP_HOST']


Which statement is true regarding the XML support in PHP?
XML validation is not provided
XML parsing is provided
All of these
the PHP XML extension implements xpath


How do you perform a strict comparison of variables for type and value?
$a === $b
$a = $b
$a == $b
None of these


Which function returns information on the PHP configuration you are using?
phpsearch();
phpconfig();
phpNotice();
phpAll();
phpinfo();


Which PHP function creates a directory on an FTP server?
ftp_mkdir()
ftp_create_dir()
ftp_chdir()
ftp_make_dir()


__construct is a
class for the object.
pseudo element for an object.
constructor for an object.
regex method for an object.


What is the right way to set a value on an object stdClass?
$variable.['value'] = 'value';
$variable['value'] = 'value';
$variable.value = 'value';
$variable->value = 'value';
$variable[value] = 'value';


Which of these assigns a value of type string to variable $x?
$x[] = "true";
$x = "true";
$x = true;


How do you specify a string literal in PHP?
'Hello there'
<<<EOD Hello there EOD;
"Hello there"
All of these


Which function allows you to split a string into an array of substrings by a string delimiter?
str(" ", $str)
explode(" ", $str)
None of these
split("", string)


Choose the correct value for $i. $i = 2; $i++;
5
4
2
3


Which control statement indicates a block of code to be repeated a number of times?
if
include
for
switch



Which function returns one or more randomly selected keys from an array?
array_rchunk()
array_rshuffle()
array_rand_pop()
array_diff_key()
array_rand()


What is the correct way to require the file "time.inc" in a manner which will halt the script upon failure?
<?php include_file("time.inc"); ?>
<?php require('time.inc'); ?>
<!--require file="time.inc"-->
<% include file="time.inc" %>


Which type is not supported by PHP?
boolean
string
array
time
integer


PHP requires instructions to be terminated at the end of each statement with a
;
</php>
}
?>


Which PHP function randomizes the order of the elements in an array?
combine()
reverse()
mix()
shuffle()


Which statement correctly declares a float variable in PHP?
$a = 1.234;
$a = 7E-10;
$a = 4.5e3;
All of these


Which function allows you to specify a start position of a string and length arguments to retrieve part of a string?
str()
substr()
parse_str()
chunk_split()


True or False : list — Assign variables as if they were an array
No
Yes


Given, the following: <?php $business = array("retail", "advertising", "computer"); echo current($business)."\n"; echo next($business)."\n"; echo $business[2]."\n"; ?> What is the output?
retail retail computer
retail computer computer
retail advertising computer
retail retail retail


The FTP functions can be used to perform the following actions on file servers:
Open a connection
Login to a connection
All of these
None of these.
Upload files


Which of the following is NOT used to specify PHP comments?
#
<!-- -->
//
/* */


What is the output of flowing code? <?php $cars=array("Volvo","BMW","Toyota"); sort($cars); $clength=count($cars); for($x=0;$x<$clength;$x++) { echo $cars[$x]; echo " "; } ?>
Volvo Toyota BMW
BMW Toyota Volvo
Volvo BMW Toyota


Which variable contains values of $_GET, $_POST, and $_COOKIE?
$_REQUEST
$_INCLUDE
$_MERGE
$_ALL


Can PHP be run on a Windows IIS server?
true
false
Only if installed on a separate partition.


Select the type of variable scope which is not supported by PHP:
Global variables
Hidden variables
Local variables
Function parameters


Which of the following is the recommended standard (short_opentag=Off) for opening and closing a PHP code block?
'<!php' to open and '!>' to close
'<%php' to open and '%>' to close
'</=' to open and '/>' to close
'<?' to open and '?>' to close
'<?php' to open and '?>' to close


An array in PHP is:
a data file.
a series of variables.
None of these
a collection of key value pairs.


What type of operator is && in PHP?
assignment operator
comparison operator
logical operator
arithmetic operator


The setcookie() function must appear _____ the <html> tag.
after
before


Can PHP scripts be embedded directly into XHTML documents?
Yes
Depends on the Operating System
No


What is the result of the following code? <?php $test =array("five", "six", 3, 4); $hold= count($test); echo $test; ?>
Array
0
2
3


True or false? We can include ("sandy.php") two times in one PHP page "my.php".
False
True


Which PHP math function would you use to round a number upwards to the nearest integer?
max()
up()
ceil()
top()


In PHP in order to access MySQL database, use the:
sql_connect() function
mysql-connect() function
mysqlconnect() function
mysqli_connect() function


Which is an example of a statement using a combined operator?
$a--
$a != $b
$a == $b
$a++
$a += $b


Which of the following is the correct way to add comments to PHP?
All listed methods are valid
/* Comment code here */
# Comment code here
// Comment code here


Which following function is used to count total number of characters in a string?
strlen();
total_chars();
num_chars();
count();
str_count();


What function is used to check if a variable is an array?
in_array()
array()
array_check()
array_exists()
is_array()


Which statement is true about PHP constants?
All of these.
They cannot contain an array.
They cannot be changed.
They are case-sensitive by default.


What will it output? <?php $var = "pontus, patrik, felix"; $var = explode(", ", $var); echo count($var); ?>
A error message.
1
3
2
4


To output information about a variable use the function
print_var()
output()
var_dump()
display_var()


When using the POST method, variables are displayed in the URL:
True
Only when posted by a form
False
Only when posted with AJAX


What is the output? <?php $boolean= true; while ($boolean) { $boolean =false; echo "false"; }
syntax error
falsefalse
false
true
None of the these


What will be the result of this code: <?php $text1 = "Test"; $text2 = "Test"; if($text1 == md5($text2)) { echo "Yes"; } else { echo "No"; }
Yes
No
PHP ERROR


If you would like to check to see if a PHP variable has data, which of the following language constructs would you use?
null().
data().
none().
empty().


Variables in PHP are represented by a dollar sign followed by the name of the variable. A valid name must NEVER start with a...
underscore.
Any of these.
number.
letter.


Which of the following displays the browser properties using PHP?
$_SERVER['HTTP_USER_AGENT']
$_SERVER['HTTP_AGENT']
$_SERVER['BROWSER_DETAIL']
$_SERVER['BROWSER_NAME']


What does the following PHP statement create? define("FIRST-NAME","John");
special characters
a variable
a definition
a constant


The PHP operator, %, which returns the remainder of an equation is called the:
floating integer
remainder
modulus
pre-increment
 




Which keyword causes a conditional loop to skip to the start of the next iteration?
begin
continue
return
end


What PHP function counts elements in an array, or properties in an object?
count()
add()
digits()
array_count()


Which of the following is valid PHP syntax?
None of these
if($a == 5) echo "a = 5";
if($a == 5) then echo "a = 5"; endif
if($a == 5) echo "a = 5"; endif


In PHP, you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings.
False
True, but double quotes will expand PHP variables and escape sequences inside it.
True, they are the same thing.


What is a large binary data object called in PHP?
lib
blurb
bin
blob


What operator is used to test if two values are identical in every way
!==
=
==
instanceof
===


To suppress error messages to the user, preface the PHP statement with
@
%
#
!


What are the default header request protocols defined in PHP?
HTML
XML
XHTML
application
All of these


What is the output from this example? $str = "My name is O\'Connor."; echo stripslashes($str);
My name is O\'Connor.
None of these
My name is OConnor.
My name is O'Connor.


Which function converts a string to all uppercase characters?
upper()
ucase()
uppercase()
strtoupper()


Which of the following statement best describes: $panther = new Animal();
Invocation of a function
Declaration of a string
Constructor
Access modifier
Instantiation of a class


Which PHP extension provides an abstract method for database retrieval?
POP
PDO
STMP
TRC


A fatal run-time error would be caught by
ERROR
E_NOTICE
E_ERROR
E_WARNING


Include files can have which file extensions?
.php
.txt
Any of these
.inc


What function converts 'Hatfields & McCoys' into 'Hatfields &amp; McCoys'?
htmlentities()
convert()
transform()
ampersand()


Which of the following is NOT a function of PHP session support?
session_pw
session_decode
session_id
session_destroy


Which function removes all HTML and PHP tags?
remove_html_php()
tag_remove()
strip_tags()
remove_tags()


Which of the following language constructs is used to terminate a running script?
eval()
kill()
exit()
break()
halt()


Choose the correct output. <?php $data = "98.8degrees"; $data = (double)$data; echo $data; ?>
98.8degrees
degrees
98
98.8


True or False? Arrays in PHP can only hold the same data type.
False
True


What is the value of $var when the following line is executed in a PHP function? unset($var);
" "
NULL
Neither of these.


Which statement would produce the output, "I love summer"?
All of these
<?php print ("I love summer"); ?>
<?php $message="I love summer"; echo $message; ?>
<?php $season="summer"; echo "I love $season" ; ?>
<?="I love summer"?>


Which function allows you to delete a file?
clearfile
remove
unlink
delete


Which function checks for the existence of a particular key?
isset()
for_each()
element()
array_key_exists()


Which PHP function will combine two arrays?
array_push()
array_merge()
array_combine()
array_sum()


Which PHP function returns an array with elements in reverse order?
array_descend()
array_reverse()
None of these
reverse()


Which of the following is false?
PHP applications must be compiled.
PHP code is embedded into HTML source code.
PHP can be used to develop web applications.
PHP can be deployed on most web servers.


In the date() function what does the 'm' format character do?
Insert month as Jan through Dec
Insert month as 01 through 12
Insert minute as 0 through 59
Insert minute as 00 through 59


Which PHP function creates an array by using one array for keys and another for its values?
array2()
$array()
combine()
array_combine()


Which of the following functions changes directory on ftp-connection?
ftp_chmod()
ftp_login()
ftp_mkdir()
ftp_connect()
ftp_chdir()


In this example code, $result = print_r($a); $a is the
property
function
argument
element


Which function sets the internal pointer of an array back to its first element?
loop()
reset()
current()
next()


The comparison $a <> $b means
$a is less than $b
$a is equal to $b
$a is greater than or less than $b
$a is not equal to $b


Which datatypes are treated as arrays?
float
integer
strings
double


In PHP the error control operator is _______
!
@
*
&


HTTP cookies can be used to:
check for SQL injections.
create client side scripts.
identify a user.
validate input fields.


What does the following output? echo (5 % 3);
None of these
15
2
1


What is the GD Library?
it's add a dozen of special new $_GLOBAL variables that gives principally informations on the user (localization, common social media cookies, etc...) - (Global iDentification)
It is a library that gives the PHP the capability to create and manipulate image files. - (Gif Draw)
It is a library that gives the PHP the capability to access and create virtual domains. - (Generated Domain)


Which function displays a formatted string?
printf()
dump()
print()
echo


Which of the following outputs a formatted string?
print("Hello %s", $name);
echo("Hello %s", $name);
printf("Hello %s", $name);
output("Hello %s", $name);


What function can be used to help prevent MySQL injection?
mysql_escape()
mysqlescapethisstring()
mysql_real_escape_string()
escape_mysql_string()
None of the above


OCI8, PostgreSQL, and SQLSRV are all examples of
All of these
database extensions available in PHP.
queries available in PHP.
form extensions available in PHP


Which function advances the internal array pointer of an array?
skip()
next()
move()
current()


What is the scope of a PHP constant?
global
variable
local
None of these


What does this function do: function my_func($variable) { return (is_numeric($variable) && $variable % 2 == 0); }
Tests whether $variable is an even number
Tests whether $variable ends in 2
Tests whether $variable is a number and contains 2
Tests whether $variable is a number and ends in 2


The only code construct allowed before a namespace declaration is the declare statement, for defining encoding of a source file
false
true


True or False: There is no difference in using the following 2 examples: echo('string'); echo 'string';
True
False
It depends on the server environment


Choose the output of the following code. Assume that today is 2009-3-19:2:45:32 pm <?php $today = date("F j, Y"); ?>
March 19, 2009
Mar 19, 09
03 19, 2009
Mar 19, 2009


Which rule determines which sections of script are able to access which variables?
Parameters
Variable Scope
Functions
Arrays


What is the difference between the include() and require() language constructs?
They handle failure differently.
There is no difference.
They handle file paths differently.
None of these.


The PHP mail() function allows you to...
send mail messages directly from a script.
send a mail message according to the IMAP protocol directly from a script.
send a mail message according to the POP3 protocol directy from a script.
None of these


Is $_SERVER['PHP_SELF'] subject to injection vulnerabilities?
No, it's safe. It can only contain paths and filenames specified by the web master.
Yes, it's vulnerable. On most servers PATH_INFO is supported, which is part of PHP_SELF


Which PHP function can be used to generate a unique ID for members of your site?
mt_random()
php_create_user()
uniqid()
unpack()


What function converts newlines to HTML line breaks in a string?
nl2br()
insert_br()
line_break()
html_line_break()
newlines()


What is meaning of PEAR?
PHP Extension and Application Register
PHP Extension and Application Repository
PHP Execution and Application Repository


How do I typecast a variable to boolean?
Both are valid statements.
$var = ($var == $var);
It's not possible to typecast variables like this.
$var = (bool)$var;


Which PHP string function is used to convert the first letter of a string to uppercase?
strtoupper()
strUpperCase()
ucfirst()
strUpperFirst()


Which type of array allows you to use textual keys so that array indices can be more descriptive?
Associative
All of these
Textual
Key


How do you create a non-public method, which can be used in a child-class?
nonpublic function Something() {
private function Something() {
protected function Something() {
parent function Something() {
preserved function Something() {


The case expression is used as part of a PHP ____.
switch statement.
try / catch condition.
All of these
if statement.


Which of the following is the scope resolution operator in PHP?
->
All of these
::
&
.=


Choose the word(s) that describe the fundamental style of programming for PHP.
procedural
object-oriented
imperative
All of these


You can call a parent class' implementation of a method which is overridden by a child class using:
parent::
This is not possible
$this->
self::
above::


What will be the result of the following: echo ucwords(strtoupper('aAaA bBbB'));
aAAA bBBB
aAaA bBbB
Aaaa Bbbb
aaaa bbbb
AAAA BBBB


Choose the output of the following script. <?php $rest = substr("abcdef", -1); echo $rest; ?>
f
a
e
0


Which function returns the contents of the output buffer and empties the buffer?
ob_get_clean();
ob_return_clean();
ob_own_clean();
ob_ret_clean();



What is output by the following: $c = 1; ++$c; echo $c++;
2
3
1
4


Choose the variable assignment which is performed 'by value' in PHP.
$value1= %$value
$value1= &$value
None of these
$value1= $value


Which PHP function sorts an array and maintains index association?
array_alpha()
sort()
awalk()
asort()


Which PHP function returns "true" if a value already exists in an array?
in_array()
array_search()
is_array()
array_found()
array_key_exists()


What is returned by array_product( array( 2, 3) )?
array( array( 2 ) )
2
3
6
array( 2 )


How would you create a numeric array from the following string that did not include "-test" and where each digit had its own array key? $str = '6.1.4.2.6-test';
$arr = implode('-', $str); $arr = implode('.', $arr[0]);
$arr = str_replace('-', '', $str);
You can't
$arr = explode('-', $str); $arr = explode('.', $arr[0]);


The interpreter executes one PHP command which ends in a semi-colon. This is referred to as a
All of these
PHP array.
PHP statement.
PHP function.


Which PHP function checks to see if a file exists and is writable?
is_writable()
write()
if_exists()
isset()


The web server sets a cookie on the web client by sending the name/value pair as part of
java protocol.
an HTTP header.
a session.
a database object.


Which PHP function sends a raw HTTP header to a client?
raw()
$_REQUEST
$_HTTP
header()


$val = ""; What will isset($val) return?
false
true
0


echo substr("Hello world",-4); the right output is?
orld
hell
world
hello


What is the default execution time for a PHP script?
60 secs
30 secs
20 secs
10 secs


After a file is successfully opened in PHP, how do you retrieve a line from the file?
!feof
line_number
fpointer
fgets


What will range('a', 'z') return?
This function call will throw an exception
An alphabetically ordered array of letters from 'a' to 'z'
Distance between letters 'a' and 'z' on an alphabetically ordered list
False


Which of the following is not a valid key type for arrays in PHP?
strings
integers
All of these
objects


natsort( array( "i10", "i1", "i20" ) ) = ?
array( "i20", "i10", "i1" )
array( "i10", "i1", "i20" )
array( "i1", "i10", "i20" )
array( "i10", "i20", "i1" )
false


What separates a sequence of one or more characters used to specify the boundary between separate text regions?
separater
delimiter
extended value
parser


What is the value of $start after exiting the for loop? <?php $start=5; for ($i=0; $i !=1; $i++) { $start= $start - 2; } ?>
2
4
3
5
1


The following code will produce: var_dump(5 === "5");
bool(true)
string(1) "5"
bool(false)
int(5)


What variable scope would you use if you wanted a function variable which does not discard it's value when the function has completed execution?
None of these
local
function parameter
static


The break statement ends execution of which of the following structures?
switch
while
All of these
for


Which PHP function tells whether a file exists and is readable?
if_exists()
isset()
is_readable()
read()


Choose the string for which the POSIX regular expression ^[A-Za-z]$ matches.
2I
P
&
67


function foo($bar) { if($bar['soap'] != 'Zest') { return $bar['soap']; } } Which best describes the function foo()?
It is an anonymous function
It will return an error
It is syntactically incorrect
It opens an infinite loop
The parameter(s) passed to it is/are an associative array


What is default session time in PHP ?
3036 Seconds
1436 Seconds
2000 Seconds
1440 Seconds


In this example code, $result = print_r ($a); $result is the
argument.
variable.
expression.
property.


Given the following code, the Atom class can access which variables? class Flash { public $fast; private $superSpeed; private $ultraSonic; protected $warp; } class Atom extends Flash { }
$superSpeed, $ultraSonic
$fast, $superSpeed, $ultraSonic, $warp
$fast, $warp
$fast, $superSpeed, $ultraSonic
$fast


Which PHP function or variable will return the value of current session id?
$_SESSION['ID']
session_id()
$_SESSION['CURRENT_ID']
curr_session_id()


What's the MIME type for images with correct extension "jpg"?
mime/.jpg
jpg
image/jpeg
mime/jpg
image/jpg


How would you delete a cookie?
use session_destroy()
use cookie_destroy()
do not set an expiration
eat it warmed with milk
set the expiration date in the past


What will be displayed? <?php $var = "6"; var_dump($var); $var++; var_dump($var); ?>
string(1) "6"
string(1) "6" int(7)
string(1) int(7)
int(7)


Which PHP function removes the last value of an array and returns it?
array_pop()
array_last()
array_unshift()
array_shift()


Which of the following string delimiting methods is known as the heredoc syntax?
delimited by single quote
delimited by <<< identifier
delimited by double quote
All of above


Self-contained collections of functions AND properties are referred to as
objects.
elements.
references.
collections.


Given the statement, mysqli_connect(“happy.com”, “hot24”, “015A#”, “ABC”); “happy.com” and “hot24” respectively refer to ?
Host, database
Password, username
Database, host
Server, client
Host, username


Error reporting constants are used to adjust error reporting settings. Which of the following is NOT a valid error reporting constant?
E_CONSTANT
E_NOTICE
E_STRICT
E_WARNING
E_ALL


What is the result of the following code: $array[]="value";
adds new element to the array with null as a key
is illegal, will throw an fatal error
adds new element at the end of the array
creates new array of chars from the given string


Which compound type is supported by PHP?
boolean
array
integer
float


In PHP, the die() and exit() language constructs perform the same function.
True
False: They produce different return codes
False: They are actually MySQL functions
False: They are not part of the PHP language


To access functions of an instantiated class, you use the following:
class::function
class.function()
class->function()
$class::function()
$class->function()


What is one of the difference between the use of single quotes and double quotes in PHP syntax?
variables names will not be expanded in double quotes
double quoted strings cannot contain line breaks
variable names will be expanded in double quotes
single quoted strings cannot contain line breaks


<?php $array1= array(“fast”, "faster”); $array1[0] = “faster”; if ($array1[1] == “faster”) { $array1[1]= “fastest”; } foreach($array1 as $output) { echo $output . " "; } ?>
fastest faster
faster fastest
faster faster
none of these
fastest fastest


Which one removes a cookie from client's browser?
setcookie('mycookie', '', time()-3600);
removecookie('mycookie', 0, time()-3600);
deletecookie($_COOKIE['mycookie']);
unsetcookie('mycookie', 0, 1);


The PHP instruction header("Content-Type: text/plain") should be sent:
after the page is loaded.
inside of a function.
in the HTML header.
before any output is sent


What do anonymous functions do in PHP?
None of these
provide functions which run at the end of a script's execution
allow the creation of functions with no name
allow the creation of global functions


Which PHP function closes an open SQLite database?
close();
sqlite_close($dbhandle);
SQLite3Stmt::close();
All of these


Which function sorts an array in descending order?
ksort()
rsort()
usort()
sort()


Which type of control structure should NOT be used to check for a condition being met?
switch
try / catch
None of these
if /else


The PHP statement: $i[2] = "orange"; is an example of
a numeric array.
None of these
an associative array.
a distributive array.


Which of the following is not a valid PHP variable declaration?
$_10
$10_var
${“MyVar”}
$aVaR


Upon completion of a file upload in PHP, the UPLOAD_ERR_OK error code is returned. What does this indicate?
The file uploaded with success.
The uploaded file was only partially uploaded.
Failed to write file to disk.
No file was uploaded.



Which statement will NOT combine strings $s1 and $s2 into a single string?
$s1 + $s2
implode(' ',array($s1,$s2))
$s1.$s2
"{$s1} {$s2}"


Which is a valid character for starting a PHP function name?
dollar sign($)
All of these
percent(%)
underscore(_)


Which of the following functions allows you to split a string by a regular expression and put the results into an array?
preg_split()
explode()
implode()
join()


dirname(__FILE__) will return what?
the current directory
The relative location of the server root
the same thing as $_SERVER['DOCUMENT_ROOT']
The URL of the file it's placed in
The directory in which the currently invoked file is located


Which libraries are available for using regular expressions in PHP?
Neither of these.
Perl-Compatible (PCRE)
POSIX Regex
Both of these.


What is the result of casting the integer 1 to an array: (array) 1
An associative array with a key of 1 and a value of 1
A numerically indexed array with one element who's value is 1
Casting an integer to an array has no effect
An associative array with a key of 1 and a value of NULL


Variable $a has not been declared. With error reporting turned off, what is the result of: $a[1][2]=3;?
Syntax error
A multi-level array structure is created with 3 as a value.
Error: Undeclared variable $a
Error: Uninitialized array $a[1]


What is default session time in PHP?
900 seconds or 15 minutes.
1800 seconds or 30 minutes.
infinity
3600 seconds or 60 minutes.
1440 seconds or 24 minutes.


What is input sanitization?
Converting input into a format that PHP supports.
All of these
The automatic process that creates the $_GET, and $_POST superglobals.
Removing or cleaning potentially malicious user input.


How can we set the default time zone using PHP?
default_timezone(timezone_identifier);
timezone_set(timezone_identifier);
date_default_timezone_set(timezone_identifier);


What function creates a cookie?
setcookie()
cookie()
establishcookie()
set_cookie()
create_cookie()


Which PHP function checks to see if HTTP headers have been sent?
header()
http_response_code()
headers_sent()
sent()


What will be the value of $result? <?php $myArr = array( 'val1' => 1, 'val2' => array('val21' => 21, 'val22' => 22), 'val3' => 3 ); $result = array_key_exists('val22', $myArr); ?>
an error
false
" "
true


Which methods are available in PHP to read a remote file?
curl_exec()
file_get_contents()
fopen()
All of these


What function can you use to create your own streams using the PHP stream wrappers and register them within PHP?
wrapper_register
stream_wrapper_register
stream_wrapper_reg


Which character is used to separate namespaces in PHP?
Arrow(->)
Backslash (\)
Double colon (::)
Period(.)


The function checkdate() returns what data type?
Timestamp
String
Boolean
Integer
Date


How to capture exception message of a try / catch? Note: consider Exception $e
$e->getMessage();
$e->error();
$e->getException();
$e->getExceptions();
$e->getErrors();


The following code does what? <?php $textfile = "my_file.txt"; $file = fopen("$textfile", 'r+'); ?>
opens the file, "my_file.txt" for reading only
reads the entire file, "my_file.txt" into an array
opens the file, “my_file.txt” for reading and writing


$table = array("old_value"); foreach($table as $row) { $row="new_value"; } echo $table[0]; will produce:
"old_value"
Fatal error, as the variable used in foreach is read-only
"new_value"


What function sets the default timezone used by all date and time functions in a script?
date_default_set('Region');
date_set('Region');
default_timezone_set('Region');
timezone_set('Region');
date_default_timezone_set('Region');      


Choose the correct output for: $x=array(2=>"mouse",7=>"keyboard"); $y=array_keys($x); echo $y[1];
7
2
mouse
keyboard


How can you call this function? $greet = function($name) { printf("Hello %s\r\n", $name); };
$greet $World;
$greet('World');
PHP does not support this syntax.


$_SERVER, $_COOKIE, $_FILES, $_ENV are examples of PHP built-in variables called:
superglobals
$_GLOBALS
global functions
global arrays


print_r( 2 ) outputs:
int(2)
Throws an exception
Nothing, but returns false
Array { [0] => 2 }
2


In PHP5, your "construct" method must be named the exact same thing as your "class".
False
Only on Nginx
Only on Lighttpd
When your class extends a parent class
True


What is the way to use the magic method '__toString()' of this Class ? class exampleClass { protected $a= 1; protected $b= 2; function __toString() { return 'a= '. $this->a . ',b= '. $this->b; } }
All of the these.
$c = new exampleClass(); $c->__toString();
$c = new exampleClass(); (string) $c;
$c = new exampleClass(); strval($c);


The comparison $a xor $b evaluates to...
TRUE if either $a or $b is FALSE
FALSE if either $a or $b is TRUE, but not both.
TRUE if either $a or $b is TRUE, but not both.
TRUE if either $a or $b is TRUE


Which of the following functions is used to format a number ?
num_format();
format_number();
format_num();
number_format();
format($number,$format_style);


To determine if the file pointer is at the end of a successfully opened file, use the...
$file_end variable.
feof() function.
eof() function.
$end variable.


Which of the following will return TRUE?
is_null(3.14)
is_numeric(M_PI)
is_string(M_PI)
is_numeric("three point one four")


Which of the following functions can be used to execute a shell command?
passthru();
exec();
system();
All of these


If one wants to convert all double quotes (") to a backslash followed by a double quote (\") which of the following can be used?
addslashes()
htmlspecialchars()
escape_quotes()
addbackslash()
None of these


Which PHP function will return an array of values from $start to $end.
array_list( $start, $end);
range( $start, $end);
list( $start, $end);
numbers( $start, $end);


The PHP function which capitalizes the first letter of each word in a string
ucfirst()
strtoupper()
caps()
ucwords()


PHP scripts can be saved, and included later, under which allowed file extensions?
.php ONLY
.inc, .common and .php
Any File Extension
.inc and .php


The function setcookie( ) is used to
All of these.
enable or disable cookie support.
create, update, or delete a cookie header in the HTTP response
send a cookie without url-encoding the cookie value.


When using php cli how can you return the same info as phpinfo()
php -c 'phpinfo();'
php -i
php -a
php -I


What is the correct way to assign a class constant?
constant MY_CONSTANT = 'value';
private MY_CONST = 'value';
const MY_CONSTANT = 'value';
const $myConstant = 'value';


Which of these is correct usage of the chmod() function?
chmod('/path/to/file', 755);
chmod('/path/to/file', 0755);
chmod('/path/to/file', '-rwxr-xr-x');
chmod('/path/to/file', 0x755);


Which of the following is true about the "touch" function in PHP? Signature: touch($filename, $time) : boolean
$time is a required parameter of this function.
If the file does not exist, it will be created.
Modification timestamp is not modified, only access time (in the filesystem)


What is the recommendation regarding PHP closing tags in a document?
There is no recommendation.
Omit the closing tag when the file contains only PHP code.
Only use the closing tag when short tags are enabled.
End all PHP files with '?>'.


Which of the following functions does not have a resource for a return type?
None of these
strrpos()
mysql_connect()
fopen()


What is PHAR?
The PHP official application and extensions repository ("PHP Application Repository")
The PHP way to distribute entire applications within a single file ("PHP Archive")
The PHP official reference on advanced topics ("PHP Advanced Reference")


What is the primary difference between interfaces and abstract classes in PHP?
Abstract classes cannot have function implementations.
Multiple Inheritance is available for an Abstract class.
Interfaces can contain variables,
Interfaces cannot have function implementations.


Which function removes the first element from an array, and returns the value of the removed element?
array_flip()
array_pop()
array_shift()
array_compare()


what is array_column?
Return the values from a single column in the input array
Return the key from a single column in the input array
Return the values from a multi column in the input array
get the values from a single column in the input obj


How do you get the number of arguments passed to a PHP function?
count() function
None of these
$argc variable
$argv variable


Which PHP function is used to replace a string?
str_replace()
substr_replace()
str_ireplace()
All of these


PHP variable $hello is set to “HELLO WORLD". Which statement would return "Hello World" instead?
echo ucwords($hello);
echo ucfirst($hello);
echo ucwords(strtolower($hello));
echo ucfirst(strtolower($hello));
 

 
 

No comments:

Post a Comment