1.Considering the code below, which of these statements are true?
<?php ini_set("allow_url_fopen", "1"); $page = file_get_contents("http://www.codepunker.com"); if($page!=FALSE) echo "Successfully fetched website contents"; else echo "An error has occurred";
The correct setting for loading web pages from a script is "allow_url_include"
The "allow_url_fopen" option can not be changed through ini_set. It can only be set in php.ini for security reasons
The if statement should be "if($page!==FALSE)" because "file_get_contents" can return non boolean values which evaluate to false
2.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
3.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
4.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
5.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
6.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
7.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]
8.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
9.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
10.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()
11.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
12.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
13.Which of the following are valid PHP variables?
Which of the following are valid PHP variables?
@$foo
&$variable
${0x0}
$0x0
14.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();
15.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();
16.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
17.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
18.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
19.Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?
Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?
You cannot disable remote PHP script execution
curl.enabled
allow_remote_url
allow_url_fopen
allow_require
20. 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
21.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)
22.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
23.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);
24.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\-]*/
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.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
27.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
28.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
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 of the following is not a valid fopen() access mode:
Which of the following is not a valid fopen() access mode:
b
x
a
w
r+