1.What output will this code produce ?
<?php class Disney { public $cartoon; function __construct($cartoon) { $this->cartoon = $cartoon; } } $disney = new Disney("The Beauty and The Beast"); $waltDisney = $disney; $waltDisney->cartoon = "Pinocchio"; echo $disney->cartoon;
"Pinocchio" because $waltDisney and $Disney are pointing to the same object
"The Beauty and The Beast" because the $cartoon property in the $waltDisney object was changed
NULL because the Disney class was not instanciated inside the $waltDisney variable
2.What is the default value for the "max_execution_time" setting when running PHP as a CLI SAPI ?
Whatever is set as the value for "max_execution_time" in php.ini
0 (Zero) which stands for infinite
There is no "max_execution_time" setting if running PHP as a CLI SAPI
3.What happens when the script below is executed ?
<?php namespace CustomArea; error_reporting(E_ALL); ini_set("display_errors", "on"); function var_dump($a) { return str_replace("Weird", $a, "Weird stuff can happen"); } $a = "In programming"; echo var_dump($a); ?>
PHP Fatal error: Cannot redeclare var_dump()
Weird stuff can happen
In programming stuff can happen
4.Considering the code below ...
<?php class AppException extends Exception { function __toString() { return "Your code has just thrown an exception: {$this->message}\n"; } } class Students { public $first_name; public $last_name; public function __construct($first_name, $last_name) { if(empty($first_name)) { throw new AppException('First Name is required', 1); } if(empty($last_name)) { throw new AppException('Last Name is required', 2); } } } try { new Students('', ''); } catch (Exception $e) { echo $e; }
... which of these statements are correct ?
The catch (Exception $e) statement is wrong because it accepts an instance of the Exception class as the parameter. It should use an instance of the AppException class instead.
catch (Exception $e)
The __toString() method can't be overwritten in a child class because the methods in the Exception class are all final but for the constructor
__toString()
Exception
The magic __toString() method will be invoked automatically when the code enters the catch() statement and the custom exception message will be printed
catch()
5.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
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.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)
8.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
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 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()
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 ____ 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
13.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
14.Which of the following will NOT instantiate a DateTime object with the current timestamp?
Which of the following will NOT instantiate a DateTime object with the current timestamp?
$date = new DateTime();
$date = new DateTime('@' . time());
$date = new DateTime('now');
$date = new DateTime(time());
15.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]'.
16.Which technique should be used to speed up joins without changing their results?
Which technique should be used to speed up joins without changing their results?
Add an index on joined columns
Add a WHERE clause
Add a LIMIT clause
Use an inner join
17.What does the following function do, when passed two integer values for $p and $q? function magic($p, $q) { return ($q == 0) ? $p: magic($q, $p % $q); }
What does the following function do, when passed two integer values for $p and $q? function magic($p, $q) { return ($q == 0) ? $p: magic($q, $p % $q); }
Loops infinitely.
Switches the values of $p and $q.
Determines if they are both even or odd?
Determines the greatest common divisor between them.
Calculates the modulus between the two.
18.What is the output of the following? $a = 20; function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;
What is the output of the following? $a = 20; function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;
120
Syntax Error
60
70
19.In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.
In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.
instanceof, is_a
instanceof, type-hinting
type, instanceof
===, type-hinting
===, is_a
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.When implementing a permissions system for your Web site, what should always be done with regards to the session?
When implementing a permissions system for your Web site, what should always be done with regards to the session?
You should not implement permission systems using sessions
Sessions should be cleared of all data and re-populated
The session key should be regenerated
The session should be destroyed
None of the above
22.Which of the following are not valid ways to embed a variable into a string?
Which of the following are not valid ways to embed a variable into a string?
$a = "Value: $value->getValue()";
$a = "Value: {$value}";
$a = 'Value: $value';
$a = "Value: $value";
$a = "Value: {$value['val']}";
23.What is the output of the following code? $string = "14302"; $string[$string[2]] = "4"; print $string;
What is the output of the following code? $string = "14302"; $string[$string[2]] = "4"; print $string;
14304
14342
44302
14402
Array
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.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
26.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
27.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
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.Consider the following function: function redirect($url) { // Check to make sure we haven't already sent // the header: if(/*???????*/) { header("Location: $url"); } } What conditional should replace the ????? above?
Consider the following function: function redirect($url) { // Check to make sure we haven't already sent // the header: if(/*???????*/) { header("Location: $url"); } } What conditional should replace the ????? above?
!in_array("Location: $url", headers_list())
!header_exists("Location: $url")
!header_location($url)
$_SERVER['HTTP_LOCATION'] != $url
30.One can ensure that headers can always be sent from a PHP script by doing what?
One can ensure that headers can always be sent from a PHP script by doing what?
Enable header buffering in PHP 5
Set the header.force INI directive to true
Enable output buffering in PHP 5
There is no way to ensure that headers can always be set, they must always be checked