1.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
2.When working with unfamiliar code, what is the best way to find out in which file a class is defined ?
Using ReflectionClass: <?php $reflection = new ReflectionClass('ClassName'); echo $reflection->getFileName(); ?>
<?php $reflection = new ReflectionClass('ClassName'); echo $reflection->getFileName(); ?>
Using the grep command to search through the application files: <?php $out = array(); exec("grep -r 'Classname' .", $out); var_dump($out); ?>
<?php $out = array(); exec("grep -r 'Classname' .", $out); var_dump($out); ?>
Using the get_declared_classes() function: $classes = get_declared_classes(); var_dump($classes);
$classes = get_declared_classes(); var_dump($classes);
3.What is the output of the code below ?
$now = new DateTime(); $now2 = new DateTime(); $ago = new DateInterval('P4Y10M3W'); $ago2 = new DateInterval('P4Y10M2W7D'); $then = $now->sub($ago); $date1 = $then->format('Y-m-d'); $then2 = $now2->sub($ago2); $date2 = $then2->format('Y-m-d'); var_dump ($date1 === $date2);
bool(false) - because the '2W' part in $ago2 will get overwritten by the '7D' part and therefor the second date interval will be 2 Weeks shorter than the first interval.
bool(false)
$ago2
bool(true) - because the two interval definitions are equivalent.
bool(true)
bool(false) and the script will throw a notice because the date/time interval notation in the $ago2 variable is wrong.
4.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
5.Which of the statements about traits below are true ?
traits
PHP is "single inheritance" so traits allow coders to reuse sets of methods from the trait freely in several independent classes
An inherited member from a base class is overridden by a member inserted by a Trait, but members from the current class override Trait methods.
If two Traits insert a method with the same name in a class that uses them, a fatal error is produced and this naming conflict can not be bypassed
6.How does Opcode Cache improve performance in PHP 5.5+ ?
Opcode Cache stores objects in memory so that they can be accessed directly by other processes.
Opcode Cache stores database query results thus eliminating the need of executing those queries again
OPcache stores precompiled script bytecode in memory, thus removing the need to load and parse scripts on each request.
7.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
8.What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);
What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);
An empty array
0.001 => 'b', .1 => c
0 => 'c'
'0.001' => 'b', '0.1' => c'
A Syntax Error
9.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()
10.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
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.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
13.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
each
import_variables
list
14.Which of the following tags are an acceptable way to begin a PHP Code block?
Which of the following tags are an acceptable way to begin a PHP Code block?
<SCRIPT LANGUAGE="php">
<!
<%
<?
15.Which of the following are valid PHP variables?
Which of the following are valid PHP variables?
@$foo
&$variable
${0x0}
$0x0
16.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" ?>
17.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
18.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.
19.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)
20.How can you modify the copy of an object during a clone operation?
How can you modify the copy of an object during a clone operation?
Put the logic in the object's constructor to alter the values
Implment your own function to do object copying
Implement the object's __clone() method
Implement __get() and __set() methods with the correct logic
Implement the __copy() method with the correct logic
21.What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?
What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?
__get($variable)
__call($method, $params)
__destruct()
__set($variable, $value)
__call($method)
22. 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
23.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
24.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
25.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']}";
26.Which function is best suited for removing markup tags from a string?
Which function is best suited for removing markup tags from a string?
strip_markup
strip_tags
str_replace
preg_replace
preg_strip
27.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);
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.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.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