Given the following code, what is correct?
function f(stdClass & $x = NULL) { $x = 42; }
$z = new stdClass;
f($z);
var_dump($z);
Which constant must be passed as the second argument to htmlentities() to convert single quotes (') to HTML entities?
Type hinting in PHP allows the identification of the following variable types: (Choose 2)
Which of the following PHP functions can be used to set the HTTP response code? (Choose 2)
You want to allow your users to submit HTML code in a form, which will then be displayed as real code and not affect your page layout. Which function do you apply to the text, when displaying it? (Choose 2)
What is the name of the PHP function used to automatically load non-yet defined classes?
Given a JSON-encoded string, which code sample correctly indicates how to decode the string to native PHP values?
Which of the following tasks can be achieved by using magic methods? (Choose 3)
What is the output of the following code?
class a
{
public $val;
}
function renderVal (a $a)
{
if ($a) {
echo $a- > val;
}
}
renderVal (null);
What will be the output value of the following code?
$array = array(1,2,3);
while (list(,$v) = each($array));
var_dump(current($array));
What is the output of the following code?
class Bar {
private $a = 'b';
public $c = 'd';
}
$x = (array) new Bar();
echo array_key_exists('a', $x) ? 'true' : 'false';
echo '-';
echo array_key_exists('c', $x) ? 'true' : 'false';
Consider the following two files. When you run test.php, what would the output look like?
test.php:
include "MyString.php";
print ",";
print strlen("Hello world!");
MyString.php:
namespace MyFramework\String;
function strlen($str)
{
return \strlen($str)*2; // return double the string length
}
print strlen("Hello world!")
What is the output of the following code?
function z($x) {
return function ($y) use ($x) {
return str_repeat($y, $x);
};
}
$a = z(2);
$b = z(3);
echo $a(3) . $b(2);
Which of the following functions will allow identifying unique values inside an array?
What is the output of the following code?
class Foo Implements ArrayAccess {
function offsetExists($k) { return true;}
function offsetGet($k) {return 'a';}
function offsetSet($k, $v) {}
function offsetUnset($k) {}
}
$x = new Foo();
echo array_key_exists('foo', $x)?'true':'false';
What is the output of the following code?
function increment ($val)
{
++$val;
}
$val = 1;
increment ($val);
echo $val;
When a query that is supposed to affect rows is executed as part of a transaction, and reports no affected rows, it could mean that: (Choose 2)
Given the following DateTime object, which sample will NOT alter the date to the value '2014-02-15'?
$date = new DateTime('2014-03-15');
What is the result of the following code?
define('PI', 3.14);
class T
{
const PI = PI;
}
class Math
{
const PI = T::PI;
}
echo Math::PI;
What is the output of the following code?
class Base {
protected static function whoami() {
echo "Base ";
}
public static function whoareyou() {
static::whoami();
}
}
class A extends Base {
public static function test() {
Base::whoareyou();
self::whoareyou();
parent::whoareyou();
Which of the following does NOT help to protect against session hijacking and fixation attacks?
What is the output of the following code?
$a = 'a'; $b = 'b';
echo isset($c) ? $a.$b.$c : ($c = 'c').'d';
Consider the following XML code:
< ?xml version="1.0" encoding="utf-8"? >
< books >
< book id="1" > PHP 5.5 in 42 Hours < /book >
< book id="2" > Learning PHP 5.5 The Hard Way < /book >
< /books >
Which of the following SimpleXML calls prints the name of the second book?
(Let $xml = simplexml_load_file("books.xml"); .) (Choose 2)
What is the output of the following code?
try {
class MyException extends Exception {};
try {
throw new MyException;
}
catch (Exception $e) {
echo "1:";
throw $e;
}
catch (MyException $e) {
echo "2:";
throw $e;
}
}
catch (Exception $e) {
echo get_class($e);
}
How many elements does the $matches array contain after the following function call is performed?
preg_match('/^(\d{1,2}([a-z]+))(?:\s*)\S+ (?=201[0-9] )/', '21st March 2014', $matches);
Consider the following code. What can be said about the call to file_get_contents?
$getdata = "foo=bar";
$opts = array('http' = >
array(
'method' = > 'POST',
'header' = > 'Content-type: application/x-www-form-urlencoded',
'content' = > $getdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);
Which line of code can be used to replace the INSERT comment in order to output "hello"?
class C {
public $ello = 'ello';
public $c;
public $m;
function __construct($y) {
$this- > c = static function($f) {
// INSERT LINE OF CODE HERE
};
$this- > m = function() {
return "h";
};
}
}
$x = new C("h");
$f = $x- > c;
echo $f($x- > m);
What is the output of this code?
$world = 'world';
echo < < < 'TEXT'
hello $world
TEXT;
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 alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
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);
What is the output of the following code?
$first = "second";
$second = "first";
echo $$$first;
Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP?
What is the output of the following code?
function ratio ($x1 = 10, $x2)
{
if (isset ($x2)) {
return $x2 / $x1;
}
}
echo ratio (0);
What is the name of the method that can be used to provide read access to virtual properties in a class?
Which string will be returned by the following function call?
$test = '/etc/conf.d/wireless';
substr($test, strrpos($test, '/')); // note that strrpos() is being called, and not strpos()
What would be the output of the following code?
namespace MyFramework\DB;
class MyClass {
static function myName() {
return __METHOD__;
}
}
print MyClass::myName();
Which of the following PHP values may NOT be encoded to a JavaScript literal using PHP's ext/json capabilities?
Which of the following expressions will evaluate to a random value from an array below?
$array = array("Sue","Mary","John","Anna");
Given a DateTime object that is set to the first second of the year 2014, which of the following samples will correctly return a date in the format '2014-01-01 00:00:01'?
Which of the following will NOT instantiate a DateTime object with the current timestamp?
One common security risk is exposing error messages directly in the browser. Which PHP configuration directive can be disabled to prevent this?
Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP, and also save the contents into another folder?
What will be the result of the following operation?
$a = array_merge([1,2,3] + [4= > 1,5,6]);
echo $a[2];
What super-global should be used to access information about uploaded files via a POST request?
Which of the following statements about anonymous functions in PHP are NOT true? (Choose 2)
What is the output of the following code?
$text = 'This is text';
$text1 = < < < 'TEXT'
$text
TEXT;
$text2 = < < < TEXT
$text1
TEXT;
echo "$text2";
Consider the following code. Which keyword should be used in the line marked with "KEYWORD" instead of "self" to make this code work as intended?
abstract class Base {
protected function __construct() {
}
public static function create() {
return new self(); // KEYWORD
}
abstract function action();
}
class Item extends Base {
public function action() { echo __CLASS__; }
}
$item = Item::create();
$item- > action(); // outputs "Item"
What is the output of the following code?
$f = function () { return "hello"; };
echo gettype($f);
Which of the following are NOT acceptable ways to create a secure password hash in PHP? (Choose 2)
What function can reverse the order of values in an array so that keys are preserved?