1.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
2.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
3.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
4.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()
5.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()
6.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
7.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
8.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
9.What is the best way to iterate and modify every element of an array using PHP 5?
What is the best way to iterate and modify every element of an array using PHP 5?
You cannot modify an array during iteration.
for($i = 0; $i < count($array); $i++) { /* ... * / }
foreach($array as $key => &$val) { /* ... * / }
foreach($array as $key => $val) { /* ... * / }
while(list($key, $val) = each($array)) { /* ... * / }
10.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
11.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();
12.What SimpleXML function is used to parse a file?
What SimpleXML function is used to parse a file?
simplexml_load_file()
simplexml_load_string()
load()
loadFile()
loadXML()
None of the above
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.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
15.What is the difference between the ``include`` and ``require`` language constructs?
What is the difference between the ``include`` and ``require`` language constructs?
Require constructs can't be used with URL filenames
Include constructs cause a fatal error if the file doesn't exist
There is no difference other than the name
Include constructs are processed at run time; require constructs are processed at compile time
Require constructs cause a fatal error if the file can't be read
16.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)
17.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
18.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
19.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
20.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
21.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()
22.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
23.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);
24.Given the two values below, which of the following possibilities will print 10 foos20 bars? $var1 = "10 foos"; $var2 = "20 bars"; print ???????;
Given the two values below, which of the following possibilities will print 10 foos20 bars? $var1 = "10 foos"; $var2 = "20 bars"; print ???????;
implode("", array($var1,$var2));
$var1 . $var2
$var1 + $var2
All of the above
25.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()
26.Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"
Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"
str_format($string, $apples, $oranges);
print($string, $apples, $oranges);
printf($string, $apples, $oranges);
print sprintf($apples, $oranges);
sprintf($string, $oranges, $apples);
27.If you would like to store your session in the database, you would do which of the following?
If you would like to store your session in the database, you would do which of the following?
It requires a custom PHP extension to change the session handler
Implement the session_set_save_handler() function
Create functions for each session handling step and use session_set_save_handler() to override PHP's internal settings
Configure the session.save_handler INI directive to your session class
28.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
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.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