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 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
3.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
4.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
5.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.
6.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
7.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()
8.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()
9.If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use?
If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use?
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
range('A', 'Z');
explode("", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
You would use the ALPHA_ARRAY constant
None of the above
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 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
12.What is the result of the following code snippet? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function something($array) { extract($array); return $c['e']; } print something($array);
What is the result of the following code snippet? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function something($array) { extract($array); return $c['e']; } print something($array);
Smith
A PHP Warning
Coggeshall
NULL
Array
13.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]'.
14.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
15.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.
16.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();
17.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
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.What are the three access modifiers that you can use in PHP objects?
What are the three access modifiers that you can use in PHP objects?
protected
public
static
private
final
20.When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?
When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?
if($obj1->equals($obj2) && ($obj1 instanceof $obj2))
if($obj1->equals($obj2))
if($obj1 instanceof $obj2)
if($obj1 === $obj2)
21.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
22.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
23.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
24.Type-hinting and the instanceof keyword can be used to check what types of things about variables?
Type-hinting and the instanceof keyword can be used to check what types of things about variables?
If a particular child class extends from it
If they are an instance of a particular interface
If they are an abstract class
If they have a particular parent class
If they are an instance of a particular class
25.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()
26.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
allow_url_fopen
27.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
28.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);
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.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()