1.What happens when you run the following MySQL Query ?
CREATE TABLE PRIMARY (ID int);
Syntax Error - PRIMARY is reserved in MySQL and should be quoted to be used as a table name
Syntax Error - PRIMARY is reserved in MySQL and can not be used as a table name
A table called PRIMARY containing a column called ID is created
2.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
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.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
5.What happens if you execute the code below ?
<?php class someclass { public $someprop; function __construct() { $this->someprop = 1; } } function somefunc(&$instance) { unset($instance); } $instance = new someclass; somefunc($instance); var_dump($instance);
NULL
object(someclass)#1 (1) { ["someprop"]=> int(1) }
Warning (Only variables can be passed by refence) NULL
6.Which from the following list is not an appropriate use of an array?
Which from the following list is not an appropriate use of an array?
As a list
All of these uses are valid
As a Lookup Table
A Stack
As a hash table
7.Which of the following functions could be used to break a string into an array?
Which of the following functions could be used to break a string into an array?
array_split()
split()
string_split()
preg_match_all()
explode()
8.The ____ construct is particularly useful to assign your own variable names to values within an array.
The ____ construct is particularly useful to assign your own variable names to values within an array.
array_get_variables
current
each
import_variables
list
9.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
10.Which one of the following XML declarations is NOT valid?
Which one of the following XML declarations is NOT valid?
<?xml version="1.0" ?>
<?xml version="1.1" encoding="UTF-8" ?>
<?xml standalone="no" ?>
<?xml standalone="1" ?>
11.Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email ------- ----------- ------------------- 1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '********'; $pdo = new PDO($dsn, $user, $pass); $cmd = "SELECT * FROM users WHERE id = :id"; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $row = $stmt->fetch(PDO::FETCH_BOUND);
Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email ------- ----------- ------------------- 1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '********'; $pdo = new PDO($dsn, $user, $pass); $cmd = "SELECT * FROM users WHERE id = :id"; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $row = $stmt->fetch(PDO::FETCH_BOUND);
The database will return no rows.
The value of $row will be an array.
The value of $result will be empty.
The value of $result will be '[email protected]'.
12.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();
13.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
14.What is wrong with the following code? function duplicate($obj) { $newObj = $obj; return $newObj; } $a = new MyClass(); $a_copy = duplicate($a); $a->setValue(10); $a_copy->setValue(20);
What is wrong with the following code? function duplicate($obj) { $newObj = $obj; return $newObj; } $a = new MyClass(); $a_copy = duplicate($a); $a->setValue(10); $a_copy->setValue(20);
You must use return &$newObj instead
There is nothing wrong with this code
duplicate() must accept its parameter by reference
You must use the clone operator to make a copy of an object
duplicate() must return a reference
15.The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.
The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.
final
protected
incomplete
abstract
implements
16.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()
17. Which of the following list of potential data sources should be considered trusted?
Which of the following list of potential data sources should be considered trusted?
$_ENV
$_GET
$__COOKIE
$_SERVER
None of the above
18.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
19.Consider the following code: header("Location: {$_GET['url']}\"); Which of the following values of $_GET['url'] would cause session fixation?
Consider the following code: header("Location: {$_GET['url']}\"); Which of the following values of $_GET['url'] would cause session fixation?
Session Fixation is not possible with this code snippet
http://www.zend.com/?PHPSESSID=123
PHPSESSID%611243
Set-Cookie%3A+PHPSESSID%611234
http%3A%2F%2Fwww.zend.com%2F%0D%0ASet-Cookie%3A+PHPSESSID%611234
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.A fingerprint of a string can be determined using which of the following?
A fingerprint of a string can be determined using which of the following?
md5()
hash()
fingerprint()
22.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()
23.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\-]*/
24.To destroy a PHP session completely, one must which of the following?
To destroy a PHP session completely, one must which of the following?
Regenerate the session ID using session_regenerate_id()
If cookies are used, destroy it
Use session_demolish() to completely destroy the session
Change the session name using session_name()
Destroy the session data using session_destroy()
25.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
26.To force a user to redirect to a new URL from within a PHP 5 script, which of the following should be used?
To force a user to redirect to a new URL from within a PHP 5 script, which of the following should be used?
Send a HTTP "Location:" header
Use the HTML <redirect> Tag
Send a HTTP "Forward:" header
Use the redirect() function
27.Setting a cookie on the client in PHP 5 can be best accomplished by:
Setting a cookie on the client in PHP 5 can be best accomplished by:
Use the add_cookie() function
Use the setcookie() function
Use the the apache_send_header() function
Setting a variable in the $_COOKIE superglobal
28.How does one create a cookie which will exist only until the browser session is terminated?
How does one create a cookie which will exist only until the browser session is terminated?
You cannot create cookies that expire when the browser session is terminated
Setting the expiration time for a cookie to a time in the distant future
Do not provide a cookie expiration time
Enable Cookie Security
Set a cookie without a domain
29.Setting a HTTP cookie on the client which is not URL-encoded is done how in PHP 5?
Setting a HTTP cookie on the client which is not URL-encoded is done how in PHP 5?
Use the setrawcookie() function
Set the cookies.urlencode INI directive to false
Use urldecode() on the return value of setcookie()
Setting the $no_encode parameter of setcookie() to a boolean 'true'
All cookies must be URL encoded
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()