1.What happens when the code below is executed ?
<?php class foo { private $variable; function __construct() { $this->variable = 1; } function __get($name) { return $this->$name; } } $a = new foo; echo $a->variable; ?>
The script outputs 1
Fatal error: Cannot access private property foo::$variable
The script outputs 0
2.What is the output of the code below ?
$now = new DateTime(); $now2 = new DateTime(); $ago = new DateInterval('P4Y10M3W'); $ago2 = new DateInterval('P4Y10M2W7D'); $then = $now->sub($ago); $date1 = $then->format('Y-m-d'); $then2 = $now2->sub($ago2); $date2 = $then2->format('Y-m-d'); var_dump ($date1 === $date2);
bool(false) - because the '2W' part in $ago2 will get overwritten by the '7D' part and therefor the second date interval will be 2 Weeks shorter than the first interval.
bool(false)
$ago2
bool(true) - because the two interval definitions are equivalent.
bool(true)
bool(false) and the script will throw a notice because the date/time interval notation in the $ago2 variable is wrong.
3.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)
4.Which of th following statements about object serialization are true ?
After serializing an object, a programmer can fully recreate that object in another file by calling unserialize() even if the class definition doesn't exist.
unserialize()
Static class properties can be serialized, but can not be unserialized.
Static class properties can not be serialized.
5.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
6.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.
7.What is the output of the following PHP script?
<?php $a = 1; $b = 2.5; $c = 0xFF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print ($f + $e);
643.75
432
643
257
432.75
8.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()
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.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
11.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()
12.Which of the following functions are used with the internal array pointer to accomplish an action?
Which of the following functions are used with the internal array pointer to accomplish an action?
key
forward
prev
current
next
13.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
14.Which of the following are valid PHP variables?
Which of the following are valid PHP variables?
@$foo
&$variable
${0x0}
$0x0
15.Given a PHP value, which sample shows how to convert the value to JSON?
Given a PHP value, which sample shows how to convert the value to JSON?
$string = json_encode($value);
$string = Json::encode($value);
$json = new Json($value); $string = $json->__toString();
$value = (object) $value; $string = $value->__toJson();
16.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
17.What is the best way to ensure that a user-defined function is always passed an object as its single parameter?
What is the best way to ensure that a user-defined function is always passed an object as its single parameter?
function myfunction(stdClass $a)
function myfunction($a = stdClass)
Use is_object() within the function
There is no way to ensure the parameter will be an object.
function myfunction(Object $a)
18.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
19.How to access standard error stream in PHP ?
How to access standard error stream in PHP ?
$stderr = STDERR;
$stderr = fopen("php://stderr", "w");
$stderr = stderr("w")
$stderr = fwrite("php://stderr");
20.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
21.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.
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.
array, interface
interface, implements
interface, extends
instance, implements
access-list, instance
22.When an object is serialized, which method will be called, automatically, providing your object with an opportunity to close any resources or otherwise prepare to be serialized?
When an object is serialized, which method will be called, automatically, providing your object with an opportunity to close any resources or otherwise prepare to be serialized?
__destroy()
__serialize()
__destruct()
__shutdown()
__sleep()
23.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
24.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)
25.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
None of the above
26.Which PCRE regular expression will match the string PhP5-rocks
Which PCRE regular expression will match the string PhP5-rocks
/^[hp1-5]*\-.*/i
/[hp1-5]*\-.?/
/[hp][1-5]*\-.*/
/[PhP]{3}[1-5]{2,3}\-.*$/
/[a-z1-5\-]*/
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.During an HTTP authentication, how does one determine the username and password provided by the browser?
During an HTTP authentication, how does one determine the username and password provided by the browser?
Parse the HTTP headers manually using http_get_headers()
Use the get_http_username() and get_http_password() functions
Use the $_SERVER['HTTP_USER'] and $_SERVER['HTTP_PASSWORD'] variables
Use the $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] variables
Parse the $_SERVER['REQUEST_URI'] variable
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()