1.What is the output of the following script ?
<?php function generate() { for ($i = 1; $i <= 3; $i++) yield $i; } $generator = generate(); if(is_array($generator)) echo "Is Array"; elseif(is_object($generator)) echo "Is Object"; else echo "Is none of the above"; ?>
Is Array
Is Object
Is none of the above
2.What is the output of the code below ?
<?php $a = array(); $a[0] = 1; unset($a[0]); echo ($a != null) ? 'True' : 'False';
True
False
Parse Error
3.What is the output of the code below ?
<?php namespace animals; ini_set('error_reporting', E_ALL); ini_set('display_errors', 'on'); class Cat { static function Definition() { return 'Cats are ' . __NAMESPACE__; } } namespace animals\pets; class Cat { static function Definition() { return 'Cats are ' . __NAMESPACE__; } } echo Cat::Definition();
Cats are animals\pets
Fatal error: Cannot redeclare class Cat
Fatal error: Cannot re-declare class animals\pets\Cat in sub-namespace
4.Assuming that the code below is in a file named "test.php" and that PHP has full rights over the file, what happens if the file is executed from the command line without any arguments ?
exec("rm -f " . dirname(__FILE__) . "/" . $argv[0]);
The script exits without doing anything
The file test.php is deleted
A notice is thrown because $argv[0] is not defined and the script fails.
$argv[0]
5.What is the output of the code below ?
<?php $a = array('one'=>'php', 'two'=>'javascript', 'three'=>'python'); $b = array('python', 'javascript', 'php'); if(array_values(array_reverse($a)) === $b) echo 'true'; else echo 'false';
Fatal error: Can't use function return value in write context
false
true
6.When running PHP's built in FastCGI Process Manager (FPM) which of the following statements are true ?
Settings initialized in the php-fpm.conf file with php_admin_flag can not be overwritten in the code through ini_set()
php-fpm.conf
php_admin_flag
ini_set()
It doesn't provide any easy way of debugging slow performing requests/scripts
The special fastcgi_finish_request() function allows PHP to finish request and flush all data while continuing to do various tasks in the background.
fastcgi_finish_request()
7.How does Opcode Cache improve performance in PHP 5.5+ ?
Opcode Cache stores objects in memory so that they can be accessed directly by other processes.
Opcode Cache stores database query results thus eliminating the need of executing those queries again
OPcache stores precompiled script bytecode in memory, thus removing the need to load and parse scripts on each request.
8.Which of the following is not valid syntax for creating a new array key?
Which of the following is not valid syntax for creating a new array key?
$a[] = "value";
$a{} = "value";
$a[0] = "value";
$a{0} = "value";
$a[$b = 0] = "value";
9.What is the output of the following code block? $a = "The quick brown fox jumped over the lazy dog."; $b = array_map("strtoupper", explode(" ", $a)); foreach ($b as $value) { print "$value "; }
What is the output of the following code block? $a = "The quick brown fox jumped over the lazy dog."; $b = array_map("strtoupper", explode(" ", $a)); foreach ($b as $value) { print "$value "; }
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
A PHP Error
Array Array Array Array Array Array Array Array Array
10.Which key will not be displayed from the following code block? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function display($item, $key) { print "$key => $item\n"; } array_walk_recursive($array, "display");
Which key will not be displayed from the following code block? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function display($item, $key) { print "$key => $item\n"; } array_walk_recursive($array, "display");
d
c
b
a
They all will be displayed
11.What should go in the missing line ????? below to produce the output shown? $array_one = array(1,2,3,4,5); $array_two = array('A', 'B', 'C', 'D', 'E'); ??????? print_r($array_three); Result: Array ( [5] => A [4] => B [3] => C [2] => D [1] => E )
What should go in the missing line ????? below to produce the output shown? $array_one = array(1,2,3,4,5); $array_two = array('A', 'B', 'C', 'D', 'E'); ??????? print_r($array_three); Result: Array ( [5] => A [4] => B [3] => C [2] => D [1] => E )
$array_three = array_merge(array_reverse($array_one), $array_two);
$array_three = array_combine($array_one, $array_two);
$array_three = array_combine(array_reverse($array_one), $array_two);
$array_three = array_merge($array_one, $array_two);
$array_three = array_reverse($array_one) + $array_two;
12.The following code snippet displays what for the resultant array? $a = array(1 => 0, 3 => 2, 4 => 6); $b = array(3 => 1, 4 => 3, 6 => 4); print_r(array_intersect($a, $b));
The following code snippet displays what for the resultant array? $a = array(1 => 0, 3 => 2, 4 => 6); $b = array(3 => 1, 4 => 3, 6 => 4); print_r(array_intersect($a, $b));
1 => 0
1 => 3, 3 => 1, 4 => 3
3 => 1, 3=> 2, 4 => 3, 4=> 6
1 => 0, 3 => 2, 4 => 6
An empty Array
13.Transactions are used to...
Transactions are used to...
guarantee high performance
secure data consistency
secure access to the database
reduce the database server overhead
reduce code size in PHP
14.What would go in place of ?????? below to make this script execute without a fatal error? $a = 1; $b = 0; /* ?????? */ $c = $a / $b;
What would go in place of ?????? below to make this script execute without a fatal error? $a = 1; $b = 0; /* ?????? */ $c = $a / $b;
quit();
die();
stop();
__halt_compiler();
exit();
15.What is the output of the following function? function &find_variable(&$one, &$two, &$three) { if($one > 10 && $one < 20) return $one; if($two > 10 && $two < 20) return $two; if($three > 10 && $three < 20) return $three; } $one = 2; $two = 20; $three = 15; $var = &find_variable($one, $two, $three); $var++; print "1: $one, 2: $two, 3: $three";
What is the output of the following function? function &find_variable(&$one, &$two, &$three) { if($one > 10 && $one < 20) return $one; if($two > 10 && $two < 20) return $two; if($three > 10 && $three < 20) return $three; } $one = 2; $two = 20; $three = 15; $var = &find_variable($one, $two, $three); $var++; print "1: $one, 2: $two, 3: $three";
1: 2, 2: 20, 3: 15
1: 3, 2: 21, 3: 16
1: 2, 2: 21, 3: 15
1: 3, 2: 20, 3: 15
1: 2, 2: 20, 3: 16
16.What is the primary difference between a method declared as static and a normal method?
What is the primary difference between a method declared as static and a normal method?
Static methods can only be called using the :: syntax and never from an instance
Static methods do not provide a reference to $this
Static methods cannot be called from within class instances
Static methods don't have access to the self keyword
There is no functional difference between a static and non-static method
17.What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?
What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?
__get($variable)
__call($method, $params)
__destruct()
__set($variable, $value)
__call($method)
18.The _______ method will be called automatically when an object is represented as a string.
The _______ method will be called automatically when an object is represented as a string.
getString()
__get()
__value()
__toString()
__getString()
19.What is the best measure one can take to prevent a cross-site request forgery?
What is the best measure one can take to prevent a cross-site request forgery?
Disallow requests from outside hosts
Add a secret token to all form submissions
Turn off allow_url_fopen in php.ini
Filter all output
Filter all input
20.For an arbitrary string $mystring, which of the following checks will correctly determine if the string PHP exists within it?
For an arbitrary string $mystring, which of the following checks will correctly determine if the string PHP exists within it?
if(strpos($mystring, "PHP") !== false)
if(!strpos($mystring, "PHP"))
if(strpos($mystring, "PHP") === true
if(strloc($mystring, "PHP") == true
if(strloc($mystring, "PHP") === false)
21.What variable reference would go in the spots indicated by ????? in the code segment below? $msg = "The Quick Brown Foxed Jumped Over the Lazy Dog"; $state = true; $retval = ""; for ($i = 0; (isset(??????)); $i++) { if($state) { $retval .= strtolower(?????); } else { $retval .= strtoupper(?????); } $state = !$state; } print $retval;
What variable reference would go in the spots indicated by ????? in the code segment below? $msg = "The Quick Brown Foxed Jumped Over the Lazy Dog"; $state = true; $retval = ""; for ($i = 0; (isset(??????)); $i++) { if($state) { $retval .= strtolower(?????); } else { $retval .= strtoupper(?????); } $state = !$state; } print $retval;
$msg{$i}
ord($msg);
chr($msg);
substr($msg, $i, 2);
22.Given the two values below, which of the following possibilities will print 10 foos20 bars? $var1 = "10 foos"; $var2 = "20 bars"; print ???????;
Given the two values below, which of the following possibilities will print 10 foos20 bars? $var1 = "10 foos"; $var2 = "20 bars"; print ???????;
implode("", array($var1,$var2));
$var1 . $var2
$var1 + $var2
All of the above
None of the above
23.Which of the following is the best way to split a string on the "-=-" pattern?
Which of the following is the best way to split a string on the "-=-" pattern?
They all are equally proper methods
str_split($string, strpos($string, "-=-"))
preg_split("-=-", $string);
explode("-=-", $string);
24.Identify the best approach to compare two variables in a binary-safe fashion
Identify the best approach to compare two variables in a binary-safe fashion
Both strcmp() and $a === $b
$a == $b
$a === $b
str_compare()
strstr()
25.Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"
Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"
str_format($string, $apples, $oranges);
print($string, $apples, $oranges);
printf($string, $apples, $oranges);
print sprintf($apples, $oranges);
sprintf($string, $oranges, $apples);
26.Which string does the following PCRE regular expression match? $regex = "/^([a-z]{5})[1-5]+([a-z]+)/";
Which string does the following PCRE regular expression match? $regex = "/^([a-z]{5})[1-5]+([a-z]+)/";
Hello34262343goodbye'
frank12345abc
hello34212343goodbye
abcdefghi12345abc
27.To destroy one variable within a PHP session you should use which method in PHP 5?
To destroy one variable within a PHP session you should use which method in PHP 5?
Unset the variable in $HTTP_SESSION_VARS
Use the session_destroy() function
Use the session_unset() function
unset the variable in $_SESSION using unset()
Any of the above are acceptable in PHP 5
28.If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?
If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?
Set the session.hash_function INI configuration directive
Use the session_set_id_generator() function
Set the session id by force using the session_id() function
Use the session_regenerate_id() function
Implement a custom session handler
29.Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?
Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?
myselectbox=array()
myselectbox[]
myselectbox['multiple']
myselectbox{'multiple'}
myselectbox
30.When uploading a file using HTTP, which variable can be used to locate the file on PHP's local filesystem?
When uploading a file using HTTP, which variable can be used to locate the file on PHP's local filesystem?
$_FILES['fieldname']['tmp_name']
$_FILES['fieldname']
$_FILES['fieldname'][0]['filename']
$_FILES['fieldname']['filename']