1.Considering the code below, which of these statements are true?
<?php ini_set("allow_url_fopen", "1"); $page = file_get_contents("http://www.codepunker.com"); if($page!=FALSE) echo "Successfully fetched website contents"; else echo "An error has occurred";
The correct setting for loading web pages from a script is "allow_url_include"
The "allow_url_fopen" option can not be changed through ini_set. It can only be set in php.ini for security reasons
The if statement should be "if($page!==FALSE)" because "file_get_contents" can return non boolean values which evaluate to false
2.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
3.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]
4.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()
5.Considering the following code which of the statements below is true ?
class entity { public $name; } $human = new entity(); $dog = new entity(); $human->name = 0; $dog->name = "";
($human == $dog)
($human === $dog)
($human->name == $dog->name)
6.When dealing with cloned objects in PHP, which of the following statements are true ?
The programmer can make use of the __clone() magic method to stop an object from being cloned.
__clone()
As of PHP 7.0.0, members of cloned objects can be accessed in a single expression without any assignments... Like this: (clone new DateTime())->format('Y');
(clone new DateTime())->format('Y');
The __clone() magic method of a class is called before the actual cloning of the object occurs allowing the programmer to alter values before the cloning process begins.
7.What is the best way to store and verify passwords in PHP ?
Using a hashing algorithm like md5 or sha256 and then, when verifying compare the stored hash with the hash of the string submitted by the user
md5
sha256
Using the built in password_create() and password_verify() functions in PHP
password_create()
password_verify()
Using the strongest to date hashing algorithm combined with a salt to avoid dictionary attacks.
salt
8.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.
9.How do you access standard I/O and error streams ?
Use stdin(), stdout() and stderr() functions
PHP::STDIN, PHP::STDOUT and PHP::STDERR class constants
Use PHP::stdin(), PHP::stdout() and PHP::stderr() class functions
STDIN, STDOUT and STDERR constants
10.Which of the following functions will sort an array in ascending order by value, while preserving key associations?
Which of the following functions will sort an array in ascending order by value, while preserving key associations?
asort()
usort()
krsort()
ksort()
sort()
11.What is the output of the following code block? $array = array(1 => 0, 2, 3, 4); array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3))); var_dump($array);
What is the output of the following code block? $array = array(1 => 0, 2, 3, 4); array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3))); var_dump($array);
1 => 1, 2 => 2, 3 => x, 4 => 4
0 => 1, 2 => 2, 3 => 3, 4 => 4, x => 3
0 => 0, 1 => 2, 2 => 3, 3 => x, 4 => 4
0 => x, 1 => 0, 2 => 1, 3 => 2, 4 => 3
1 => 1, 3 => x, 2 => 2, 4 => 4
12.Which function would you use to add an element to the beginning of an array?
Which function would you use to add an element to the beginning of an array?
array_shift()
array_push()
$array[0] = "value";
array_unshift()
array_pop()
13.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
14.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;
15.Given the following array: $array = array(1,1,2,3,4,4,5,6,6,6,6,3,2,2,2); The fastest way to determine the total number a particular value appears in the array is to use which function?
Given the following array: $array = array(1,1,2,3,4,4,5,6,6,6,6,3,2,2,2); The fastest way to determine the total number a particular value appears in the array is to use which function?
array_total_values
array_count_values
A foreach loop
count
a for loop
16.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
17.What is the output of the following PHP code? define("FOO", 10); $array = [10 => FOO,"FOO" => 20]; print $array[$array[FOO]] * $array["FOO"];
What is the output of the following PHP code? define("FOO", 10); $array = [10 => FOO,"FOO" => 20]; print $array[$array[FOO]] * $array["FOO"];
FOO
100
200
20
10
18.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
19.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();
20.What would you replace ??????? with, below, to make the string Hello, World! be displayed? function myfunction() { /* ??????? */ print $string; } myfunction("Hello, World!");
What would you replace ??????? with, below, to make the string Hello, World! be displayed? function myfunction() { /* ??????? */ print $string; } myfunction("Hello, World!");
There is no way to do this.
$string = $argv[1];
$string = $_ARGV[0];
list($string) = func_get_args();
$string = get_function_args();
21.How does one access standard input/output and error streams in PHP 5?
How does one access standard input/output and error streams in PHP 5?
22.How can you modify the copy of an object during a clone operation?
How can you modify the copy of an object during a clone operation?
Put the logic in the object's constructor to alter the values
Implment your own function to do object copying
Implement the object's __clone() method
Implement __get() and __set() methods with the correct logic
Implement the __copy() method with the correct logic
23.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
24.Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?
Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?
You cannot disable remote PHP script execution
curl.enabled
allow_remote_url
allow_url_fopen
allow_require
25.Which of the following php.ini directives should be disabled to improve the outward security of your application?
Which of the following php.ini directives should be disabled to improve the outward security of your application?
safe_mode
magic_quotes_gpc
register_globals
display_errors
26.Consider the following code: session_start(); if(!empty($_REQUEST['id']) && !empty($_REQUEST['quantity'])) { $id = scrub_id($_REQUEST['id']); $quantity = scrub_quantity($_REQUEST['quantity']) $_SESSION['cart'][] = array('id' => $id, 'quantity' => $quantity) } /* .... */ What potential security hole would this code snippet produce?
Consider the following code: session_start(); if(!empty($_REQUEST['id']) && !empty($_REQUEST['quantity'])) { $id = scrub_id($_REQUEST['id']); $quantity = scrub_quantity($_REQUEST['quantity']) $_SESSION['cart'][] = array('id' => $id, 'quantity' => $quantity) } /* .... */ What potential security hole would this code snippet produce?
Cross-Site Scripting Attack
There is no security hole in this code
Code Injection
SQL Injection
Cross-Site Request Forgery
27.When comparing two strings, which of the following is acceptable?
When comparing two strings, which of the following is acceptable?
$a === $b;
strcasecmp($a, $b);
strcmp($a, $b);
$a == $b;
str_compare($a, $b);
28.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);
29.If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?
If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?
strtok() using regular expressions
preg_* regular expression functions
parse_str() using regular expressions
strregex* regular expression functions
ereg* regular expression functions
30.Which functions would be needed to translate the following string: I love PHP 5 to the following? 5 PHP EVOL I
Which functions would be needed to translate the following string: I love PHP 5 to the following? 5 PHP EVOL I
mirror()
strtoupper()
toupper()
str_reverse()
strrev()