200-530 | 200-550 | 200-710
What is the output of the following code?
echo '1' . (print '2') + 3;
What is the output of the following code?
$a = 3;
switch ($a) {
case 1: echo 'one'; break;
case 2: echo 'two'; break;
default: echo 'four'; break;
case 3: echo 'three'; break;
}
What is "instanceof" an example of?
Which of the following may be used in conjunction with CASE inside a SWITCH statement?
What is the output of the following code?
$a = 'a'; $b = 'b'; echo isset($c) ? $a.$b.$c : ($c = 'c').'d';
What super-global should be used to access information about uploaded files via a POST request?
What is the difference between "print" and "echo"?
What is the output of the following code?
echo "1" + 2 * "0x02";
What is the result of the following bitwise operation in PHP?
1 ^ 2
What is the output of the following code?
echo "22" + "0.2", 23 . 1;
What is the output of the following code?
$first = "second"; $second = "first"; echo $$$first;
Your supervisor wants you to disallow PHP scripts to open remote HTTP and FTP resources using PHP's
file functions. Which php.ini setting should you change accordingly?
Which of the following code snippets DO NOT write the exact content of the file "source.txt" to "target.txt"?
(Choose 2)
What is the recommended method of copying data between two opened files?
Which PHP function sets a cookie whose value does not get URL encoded when sending it to the
browser?
Which of the following will set a 10 seconds read timeout for a stream?
What function allows resizing of PHP's file write buffer?
What does the __FILE__ constant contain?
What can prevent PHP from being able to open a file on the hard drive (Choose 2)?
What purpose do namespaces fulfill?
When would you use classes and when would you use namespaces?
Which of these elements can be encapsulated by namespaces and made accessible from the outside?
You'd like to use the class MyDBConnection that's defined in the
MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace, but you want to minimize *as much
as possible* the length of the class name you have to type. What would you do?
How should you track errors on your production website?
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 are valid identifiers? (Choose 3)
Which of the following methods are available to limit the amount of resources available to PHP through
php.ini? (Choose 2)
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!")
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 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);
What is the output of the following code?
$f = function () { return "hello"; };
echo gettype($f);
What is the output of the following code?
class C {
public $x = 1;
function __construct() { ++$this->x; }
function __invoke() { return ++$this->x; }
function __toString() { return (string) --$this->x; }
}
$obj = new C();
echo $obj();
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"
Which SPL class implements fixed-size storage?
In order to create an object storage where each object would be stored only once, you may use which of
the following? (Choose 2)
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();
A::whoareyou();
static::whoareyou();
}
public static function whoami() {
echo "A ";
}
}
class B extends A {
public static function whoami() {
echo "B ";
}
}
B::test();
Late static binding is used in PHP to:
What is the output of the following code?
class Test {
public function __call($name, $args) {
call_user_func_array(array('static', "test$name"), $args);
}
public function testS($l) {
echo "$l,";
}
}
class Test2 extends Test {
public function testS($l) {
echo "$l,$l,";
}
}
$test = new Test2();
$test->S('A');
Which of the following tasks can be achieved by using magic methods? (Choose 3)
How should class MyObject be defined for the following code to work properly? Assume $array is an array and MyObject is a user-defined class.
$obj = new MyObject(); array_walk($array, $obj);
# __invoke()
# The __invoke() method gets called when the object is called as a function.
# When you declare it, you say which arguments it should expect. Here's a trivially simple example:
class Butterfly {
public function __invoke() {
echo "flutter";
}
}
# We can instantiate a Butterfly object, and then just use it like a function:
$bob = new Butterfly();
$bob(); // flutter
Source: http://lornajane.net/posts/2012/phps-magic-__invoke-method-and-the-callable-typehint
Consider the following code. What change must be made to the class for the code to work as written?
class Magic {
protected $v = array("a" => 1, "b" => 2, "c" => 3);
public function __get($v) {
return $this->v[$v];
}
}
$m = new Magic();
$m->d[] = 4;
echo $m->d[0];
SimpleXML provides the ability to iterate over items in an XML document, as well as access items within it
as if they were object properties. When creating your own classes to access data, implementing which of
the following would NOT achieve this goal?
Which of the following is used to find all PHP files under a certain directory?
Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really
been uploaded via HTTP?
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 is the name of the key for the element in $_FILES['name'] that contains the provisional name of the
uploaded file?
What is the name of the key in $_FILES['name'] that contains the number of bytes of the uploaded file?
What information can be used to reliably determine the type of an uploaded file?
Which MIME type is always sent by a client if a JPEG file is uploaded via HTTP?
Your application uses PHP to accept and process file uploads. It fails to upload a file that is 5 MB in size,
although upload_max_filesize is set to "10M". Which of the following configurations could be responsible
for this outcome? (Choose 2)
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.infoPHP 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 alpha@example.com 2 betty beta@example.org 3 clara gamma@example.net 5 sue sigma@example.infoPHP code (assume the PDO connection is correctly established):
$dsn = 'mysql:host=localhost;dbname=exam';
$user = 'username';
$pass = '********';
$pdo = new PDO($dsn, $user, $pass);
try {
$cmd = "INSERT INTO users (id, name, email) VALUES (:id, :name, :email)";
$stmt = $pdo->prepare($cmd);
$stmt->bindValue('id', 1);
$stmt->bindValue('name', 'anna');
$stmt->bindValue('email', 'alpha@example.com');
$stmt->execute();
echo "Success!";
} catch (PDOException $e) {
echo "Failure!";
throw $e;
}
Consider the following table data and PHP code. What is a possible 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.infoPHP 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 name, email FROM users LIMIT 1"; $stmt = $pdo->prepare($cmd); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_BOTH); $row = $result[0];
Consider the following table data and PHP code, and assume that the database supports transactions. 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.infoPHP code (assume the PDO connection is correctly established):
$dsn = 'mysql:host=localhost;dbname=exam';
$user = 'username';
$pass = '********';
$pdo = new PDO($dsn, $user, $pass);
try {
$pdo->exec("INSERT INTO users (id, name, email) VALUES (6, 'bill', 'delta@example.com')");
$pdo->begin();
$pdo->exec("INSERT INTO users (id, name, email) VALUES (7, 'john', 'epsilon@example.com')");
throw new Exception();
} catch (Exception $e) {
$pdo->rollBack();
}
Given a PHP value, which sample shows how to convert the value to JSON?
Given a JSON-encoded string, which code sample correctly indicates how to decode the string to native
PHP values?
Which of the following PHP values may NOT be encoded to a JavaScript literal using PHP's ext/json
capabilities?
Which of the following will NOT instantiate a DateTime object with the current timestamp?
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'?
Given the following DateTime objects, what can you use to compare the two dates and indicate that
$date2 is the later of the two dates?
$date1 = new DateTime('2014-02-03');
$date2 = new DateTime('2014-03-02');
Given the following DateTime object, which sample will NOT alter the date to the value '2014-02- 15'?
$date = new DateTime('2014-03-15');
Which interfaces could class C implement in order to allow each statement in the following code to work?
(Choose 2)
$obj = new C();
foreach ($obj as $x => $y) {
echo $x, $y;
}
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?
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';
Assuming UTF-8 encoding, what is the value of $count?
$data = '$1Ä2'; $count = strlen($data);
$data = '$1Ä2'; echo strlen($data); // 5 echo mb_strlen($data); // 4
What is the output of this code?
$world = 'world';
echo <<<'TEXT'
hello $world
TEXT;
Given a php.ini setting of
default_charset = utf-8what will the following code print in the browser?
header('Content-Type: text/html; charset=iso-8859-1');
echo '✂✔✝';
What will the following code print out?
$str = '✔ one of the following';
echo str_replace('✔', 'Check', $str);
What is the pattern modifier for handling UTF-8 encoded preg_* functionality?
What is the output of the following code?
$text = 'This is text'; $text1 = <<<'TEXT' $text TEXT; $text2 = <<<TEXT $text1 TEXT; echo "$text2";
Your public web application needs to provide access to binary files for registered users only. How would
you achieve this?
What content-type is required when sending an HTTP POST using JavaScript to ensure that PHP can
access the data?
From your PHP application, how can you send the same header twice, but with different values?
Which class of HTTP status codes is used for server error conditions?
Which class of HTTP status codes is used for redirections?
Which of the following can NOT be used to send a cookie from within a PHP application?
Under what condition may HTTP headers be set from PHP if there is content echoed prior to the header
function being used?
Before the headers are sent, how can you remove a previously set header?
How can you determine whether a PHP script has already sent cookies to the client?
An HTML form has two submit buttons. After submitting the form, how can you determine with PHP which
button was clicked?
What is the output of the following code?
function append($str) {
$str = $str.'append';
}
function prepend(&$str) {
$str = 'prepend'.$str;
}
$string = 'zce';
append(prepend($string));
echo $string;
What is the output of the following code?
function increment ($val) {
$val = $val + 1;
}
$val = 1;
increment ($val);
echo $val;
function increment ($val) {
$val = $val + 1;
}
$val = 1;
increment ($val);
echo $val; // output = 1
function increment (&$val) {
$val = $val + 1;
}
$val = 1;
increment ($val);
echo $val; // output = 2
What is the output of the following code?
function increment ($val) {
++$val;
}
$val = 1;
increment ($val);
echo $val;
function increment ($val) {
++$val;
}
$val = 1;
increment ($val);
echo $val; // output = 1
function increment (&$val) {
++$val;
}
$val = 1;
increment ($val);
echo $val; // output = 2
What is the output of the following code?
function increment ($val) {
$_GET['m'] = (int) $_GET['m'] + 1;
}
$_GET['m'] = 1;
echo $_GET['m'];
How many times will the function counter() be executed in the following code?
function counter($start, &$stop) {
if ($stop > $start) {
return;
}
counter($start--, ++$stop);
}
$start = 5;
$stop = 2;
counter($start, $stop);
1x counter(5, 2) // $start = 5, $stop = 2 2x counter(5, 3) // $start-- = 5, ++$stop = 3 3x counter(5, 4) // $start-- = 5, ++$stop = 4 4x counter(5, 5) // $start-- = 5, ++$stop = 5 5x counter(5, 6) // $start-- = 5, ++$stop = 6Incrementing/Decrementing Operators: http://php.net/manual/en/language.operators.increment.php
How do you allow the caller to submit a variable number of arguments to a function?
What will the $array array contain at the end of this script?
function modifyArray (&$array) {
foreach ($array as &$value) {
$value = $value + 1;
}
$value = $value + 2;
}
$array = array (1, 2, 3);
modifyArray($array);
What is the output of the following code?
class a {
public $val;
}
function renderVal (a $a) {
if ($a) {
echo $a->val;
}
}
renderVal (null);
What is the output of the following code?
function fibonacci (&$x1 = 0, &$x2 = 1) {
$result = $x1 + $x2;
$x1 = $x2;
$x2 = $result;
return $result;
}
for ($i = 0; $i < 10; $i++) {
echo fibonacci() . ',';
}
What is the output of the following code?
function ratio ($x1 = 10, $x2) {
if (isset ($x2)) {
return $x2 / $x1;
}
}
echo ratio (0);
Which of the following is NOT a valid function declaration?
What is the output of the following code?
function increment (&$val) {
return $val + 1;
}
$a = 1;
echo increment ($a);
echo increment ($a);
Which of the following is true about stream contexts? (Choose 2)
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);
What function can be used to retrieve an array of current options for a stream context?
When retrieving data from URLs, what are valid ways to make sure all file_get_contents calls send a
certain user agent string? (Choose 2)
What will an opcode cache ALWAYS automatically improve?
What is cached by an opcode cache?
Which php.ini setting is usually required to use an opcode cache?
What is the output of the following code?
var_dump(boolval(-1));
What is the output of the following code?
var_dump(boolval([]));
What is the output of the following code?
var_dump(boolval(new StdClass()));
Consider the following code:
$result = $value1 ??? $value2;Which operator needs to be used instead of ??? so that $result equals $value1 if $value1 evaluates to true, and equals $value2 otherwise? Just state the operator as it would be required in the code.
Which of the following is NOT true about PHP traits? (Choose 2)
Given the following code, what will the output be:
trait MyTrait {
private $abc = 1;
public function increment() {
$this->abc++;
}
public function getValue() {
return $this->abc;
}
}
class MyClass {
use MyTrait;
public function incrementBy2() {
$this->increment();
$this->abc++;
}
}
$c = new MyClass;
$c->incrementBy2();
var_dump($c->getValue());
Given the following code, how can we use both traits A and B in the same class? (select all that apply)
trait A {
public function hello() {
return "hello";
}
public function world() {
return "world";
}
}
trait B {
public function hello() {
return "Hello";
}
public function person($name) {
return ":$name";
}
}
In the following code, which line should be changed so it outputs the number 2:
class A {
protected $x = array(); /* A */
public function getX() { /* B */
return $this->x; /* C */
}
}
$a = new A(); /* D */
array_push($a->getX(), "one");
array_push($a->getX(), "two");
echo count($a->getX());
What is the output of the following code?
class A {
public $a = 1;
public function __construct($a) { $this->a = $a; }
public function mul() {
return function($x) {
return $this->a*$x;
};
}
}
$a = new A(2);
$a->mul = function($x) {
return $x*$x;
};
$m = $a->mul();
echo $m(3);
$m = $a->mul(); echo $m(3); // output is 6
$m = $a->mul; echo $m(3); // output is 9
What is the output of the following code?
class Number {
private $v = 0;
public function __construct($v) { $this->v = $v; }
public function mul() {
return function ($x) { return $this->v * $x; };
}
}
$one = new Number(1);
$two = new Number(2);
$double = $two->mul()->bindTo($one);
echo $double(5);
What is the output of the following code?
class Number {
private $v;
private static $sv = 10;
public function __construct($v) { $this->v = $v; }
public function mul() {
return static function ($x) {
return isset($this) ? $this->v*$x : self::$sv*$x;
};
}
}
$one = new Number(1);
$two = new Number(2);
$double = $two->mul();
$x = Closure::bind($double, null, 'Number');
echo $x(5);
Which of the following statements about anonymous functions in PHP are NOT true? (Choose 2)
What will be the result of the following operation?
$a = array_merge([1,2,3] + [4=>1,5,6]); echo $a[2];
Which of the following functions will allow identifying unique values inside an array?
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
/* output
Array
(
[1] => 2
[hello] => 2
[world] => 1
)
*/
When using password_hash() with the PASSWORD_DEFAULT algorithm constant, which of the following
is true? (Choose 2)
Which of the following are NOT acceptable ways to create a secure password hash in PHP? (Choose 2)
What is the preferred method for preventing SQL injection?
Is the following code vulnerable to SQL Injection ($mysqli is an instance of the MySQLi class)?
$age = $mysqli->real_escape_string($_GET['age']); $name = $mysqli->real_escape_string($_GET['name']); $query = "SELECT * FROM `table` WHERE name LIKE '$name' AND age = $age"; $results = $mysqli->query($query);
// SQL injections $query = "SELECT id, title, body FROM posts WHERE id = " . mysql_real_escape_string($_GET['id']); // This can still be injected: 1 OR 1=1 // Resulting in: SELECT id, title, body FROM posts WHERE id = 1 OR 1=1 // All results are returned. Not convinced this is bad? Ok... 1 OR 1=1 UNION SELECT id, username, password FROM users // Whoops! Why is this injectable? The developer just forgot to quote the numeric ID.Source: http://stackoverflow.com/questions/16173027/mysql-real-escape-string-not-escaping-all-types-of
Which of the following does NOT help to protect against session hijacking and fixation attacks?
Please provide the value of the $code variable in the following statement to set an HTTP status code that
signifies that the requested resource was not found.
http_response_code($code);
Which of the following PHP functions can be used to set the HTTP response code? (Choose 2)
What is the name of the header used to require HTTP authentication?
What types of HTTP authentication are supported by PHP? (Choose 2)
Which of the following items in the $_SERVER superglobal are important for authenticating the client
when using HTTP Basic authentication? (Choose 2)
When tracking upload progress with sessions, the values of 2 INI settings are needed to determine the
key in $_SESSION of the upload progress data. What are the INI settings? (Choose 2)
What is the name of the function that allows you register a set of functions that implement user- defined
session handling?
Which of these databases is NOT supported by a PDO driver?
Which of these statements about PDO is NOT true?
What is the output of the following code?
class test {
public $value = 0;
function test() {
$this->value = 1;
}
function __construct() {
$this->value = 2;
}
}
$object = new test();
echo $object->value;
Which methods can be used to overload object properties? (Choose 2)
What is the result of the following code?
class T {
const A = 42 + 1;
}
echo T::A;
Which of the following statements is NOT true?const MY_CONSTANT; echo MY_CONSTANT; // Output: syntax error, unexpected ';', expecting '='
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;
Given the following code, what is correct?
function f(stdClass &$x = NULL) { $x = 42; }
$z = new stdClass;
f($z);
var_dump($z);
Which of the following statements is NOT correct?
Which of the following statements is correct?
Which of the following statements about exceptions is correct? (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);
}
Which of the following is NOT possible using reflection?
What is the name of the method that can be used to provide read access to virtual properties in a class?
Which of the following statements about Reflection is correct?
What is the name of the PHP function used to automatically load non-yet defined classes?
When a class is defined as final it:
Type hinting in PHP allows the identification of the following variable types: (Choose 2)
In the following code, which classes can be instantiated?
abstract class Graphics {
abstract function draw($im, $col);
}
abstract class Point1 extends Graphics {
public $x, $y;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
function draw($im, $col) {
ImageSetPixel($im, $this->x, $this->y, $col);
}
}
class Point2 extends Point1 { }
abstract class Point3 extends Point2 { }
Which of the following code snippets is correct? (Choose 2)
Which of the following statements about PHP is false? (Choose 2)
Which of the following is correct? (Choose 2)
Which of the following functions are used to escape data within the context of HTML? (Choose 2)
In a shared hosting environment, session data can be read by PHP scripts written by any user.
How can you prevent this? (Choose 2)
Which of the following filtering techniques prevents all cross-site scripting (XSS) vulnerabilities?
You work for a shared hosting provider, and your supervisor asks you to disable user scripts to dynamically load PHP extensions using the dl() function. How can you do this? (Choose 2)
When a browser requests an image identified by an img tag, it never sends a Cookie header.
Which of the following techniques ensures that a value submitted in a form can only be yes or no ?
Which function can NOT help prevent cross-site scripting? (Choose 2)
Which constant must be passed as the second argument to htmlentities() to convert single quotes (') to
HTML entities?
One common security risk is exposing error messages directly in the browser. Which PHP configuration
directive can be disabled to prevent this?
Which of the following superglobals does not necessarily contain data from the client?
Which of the following statements is true?
Transactions are used to...
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)
Transactions should be used to: (Choose 2)
An unbuffered database query will: (Choose 2)
Which technique should be used to speed up joins without changing their results?
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 method can be used to find the tag <any> via the DOM extension?
What DOMElement method should be used to check for availability of a non-namespaced attribute?
Which of the following is an invalid DOM save method?
Which of the following rules must every correct XML document adhere to? (Choose 2)
Which one of the following XML declarations is NOT valid?
Which of the following parts must a XML document have in order to be well-formed?
Which of the following can be registered as entry points with a SoapServer instance (choose 2):
Which of the following statements about SOAP is NOT true?
What SimpleXML function is used to parse a file?
The XML document below has been parsed into $xml via SimpleXML. How can the value of <foo> tag
accessed?
<?xml version='1.0'?>
<document>
<bar>
<foo>Value</foo>
</bar>
</document>
What parsing methodology is utilized by the SimpleXML extension?
How can the id attribute of the 2nd baz element from the XML string below be retrieved from the
SimpleXML object
found inside $xml?
<?xml version='1.0'?>
<foo>
<bar>
<baz id="1">One</baz>
<baz id="2">Two</baz>
</bar>
</foo>
How can a SimpleXML object be converted to a DOM object?
What is the method used to execute XPath queries in the SimpleXML extension?
Which of the following statements are FALSE?
What DOM method is used to load HTML files?
What is the output of the following code?
for ($i = 0; $i < 1.02; $i += 0.17) {
$a[$i] = $i;
}
echo count($a);
After performing the following operations:
$a = array('a', 'b', 'c');
$a = array_keys(array_flip($a));
What will be the value of $a?
PHP's array functions such as array_values() can be used on an object if the object...
Which is the most efficient way to determine if a key is present in an array, assuming the array has no
NULL values?
// isset() does not return TRUE for array keys that correspond to a NULL value, while array_key_exists() does.
$search_array = array('first' => null, 'second' => 4);
// returns false
isset($search_array['first']);
// returns true
array_key_exists('first', $search_array);
An object can be counted with count() and sizeof() if it...
Which value will be assigned to the key 0 in this example?
$foo = array(true, '0' => false, false => true);
What will be the result of the following operation?
array_combine(array("A","B","C"), array(1,2,3));
Which of the following expressions will evaluate to a random value from an array below?
$array = array("Sue","Mary","John","Anna");
What function can reverse the order of values in an array so that keys are preserved?
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 will be the output of the following code?
$a = array(0, 1, 2 => array(3, 4)); $a[3] = array(4, 5); echo count($a, 1);
Given the following array:
$a = array(28, 15, 77, 43);Which function will remove the value 28 from $a?
The constructs for(), foreach(), and each() can all be used to iterate an object if the object...
Which parts of the text are matched in the following regular expression?
$text = <<<EOT
The big bang bonged under the bung.
EOT;
preg_match_all('@b.n?g@', $text, $matches);
What will the following code piece print?
echo strtr('Apples and bananas', 'ae', 'ea')
Apples end benenes // 1st: change a -> e, note Apples has not been changed Applas end benenes // 2nd: change e -> a, only where it has not been changed yet, that is, Apples change to Applas
You want to parse a URL into its single parts. Which function do you choose?
Which elements does the array returned by the function pathinfo() contain?
What will the following function call print?
printf('%010.6f', 22);
What is the output of the following code?
echo 0x33, ' monkeys sit on ', 011, ' trees.';
You want to access the 3rd character of a string, contained in the variable $test. Which of the following
possibilites work? (Choose 2)
Which sentence describes the following regular expression match?
preg_match('/^\d+(?:\.[0-9]+)?$/', $test);
You need to escape special characters to use user input inside a regular expression. Which functions
would you use? (Choose 2)
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);
How many elements does the array $matches from the following code contain?
$str = "The cat sat on the roof of their house.";
$matches = preg_split("/(the)/i", $str, -1, PREG_SPLIT_DELIM_CAPTURE);
Given the default PHP configuration, how can all of the parameters provided via GET be accessed in a
form of a string?
What is the length of a string returned by:
md5(rand(), TRUE);
What is the return value of the following code?
strpos("me myself and I", "m", 2)
What is the return value of the following code: substr_compare("foobar", "bar", 3);
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)
How many elements does the array $pieces contain after the following piece of code has been executed?
$pieces = explode("/", "///");
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()
An HTML form contains this form element:
<input type="file" name="myFile" />When this form is submitted, the following PHP code gets executed:
move_uploaded_file( $_FILES['myFile']['tmp_name'], 'uploads/' . $_FILES['myFile']['name'] );Which of the following actions must be taken before this code may go into production? (Choose 2)
Which PHP function retrieves a list of HTTP headers that have been sent as part of the HTTP response
or are ready to be sent?
Which options do you have in PHP to set the expiry date of a session?
The following form is loaded in a browser and submitted, with the checkbox activated:
<form method="post">
<input type="checkbox" name="accept" />
</form>
In the server-side PHP code to deal with the form data, what is the value of $_POST['accept'] ?
When uploading a file to a PHP script using the HTTP PUT method, where would the file data be found?
Please provide the name of the super-global variable where all the information about cookies is available.
The following form is loaded in a recent browser and submitted, with the second select option selected:
<form method="post">
<select name="list">
<option>one</option>
<option>two</option>
<option>three</option>
</select>
</form>
In the server-side PHP code to deal with the form data, what is the value of $_POST['list'] ?
Which of the following is NOT a requirement for file uploads to work?
An HTML form contains this form element:
<input type="image" name="myImage" src="image.png" />The user clicks on the image to submit the form. How can you now access the relative coordinates of the mouse click?
Which PHP function sets a cookie and URL encodes its value when sending it to the browser?
What elements will the following script output?
<?php $array = array(true => 'a', 1 => 'b'); print_r($array); ?>
What is the output of the following code:
<?php
echo str_replace(array("Apple","Orange"), array("Orange","Apple"), "Oranges are orange and Apples are green");
?>
Which of the following statements about Reflection are correct? [ Choose 2 ]
Which DOM Element property provides a reference to the list of the element's children?
When you need to process the values of columns in a database, you should:
What PHP function can be used to remove a local file?
Which of the following functions can help prevent session fixation vulnerabilities?
When working with the MVC paradigm, the business logic should be implemented in which of the following components?
You want to present the following formatted number: "999.000.000,00". Which function call is correct?
Can a private static member be accessed from a public static method of the same class?
class C {
private static $x = 5;
public static function getX() {
return self::$x;
}
}
echo C::getX(); // 5
What is the difference between isset() and other is_*() functions (is_alpha(), is_number(), etc.)?
Consider the following script:
<html>
<head>
<title>
This is a test script.
</title>
</head>
<body>
<?php
echo 'This is some sample text';
?>
</body>
</html>
Which of the following equivalence operations evaluates to true if the two operands are not of the same data type or do not have the same value?
Consider the following code:
<?php
$a=5;
$b=12;
$c=10;
$d=7;
$e=($a*$b)+$c*$d/$a;
print($e);
?>
What will be the output of the above code?
You work as a Web Developer for Remote Inc. What will be the output when you try to run the script below?
<?php
$b = false;
if($b = true)
print("true");
else
print("false");
?>
Which of the following options is/are correct regarding variable scopes in PHP?
You run the following PHP script:
<?php
for($x = 1; $x <= 2; $x++){
for($y = 1; $y <= 3; $y++){
if ($x == $y) continue;
print("x = $x y = $y");
}
}
?>
What will be the output? Each correct answer represents a complete solution. Choose all that apply.
What is the result when the following PHP code involving a boolean cast is executed?
<?php var_dump( (bool) 5.8 ); ?>
the boolean FALSE itself
the integer 0 (zero)
the float 0.0 (zero)
the empty string, and the string "0"
an array with zero elements
the special type NULL (including unset variables)
SimpleXML objects created from empty tags
Every other value is considered TRUE (including any resource and NAN).
Which of the below provided options is correct regarding the below code?
<?php
$a = array (1, 2, 3);
$b = array (1 => 2, 2 => 3, 0 => 1);
$c = array ('a' => 1, 'b' => 2, 'c' => 3);
var_dump ($a == $b);
var_dump ($a === $b);
var_dump ($a == $c);
?>
Which one of the following four logical operators of PHP is not binary?
What does the following function do, when passed two integer values for $p and $q?
<?php
function magic($p, $q) {
return ($q == 0) ? $p : magic($q, $p % $q);
}
?>
Consider the following script:
<?php
echo strtotime("january 1, 1901");
?>
What will be the output of the above PHP script if the older versions of glibc are present in the operating system?
Consider the following script:
<?php
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1995));
?>
What will be the output of the above script?
Mark works as a Web Application Developer for Blue Solutions Inc. He writes the following code:
<?php
$x =25;
while($x<10) {
$x--;
}
print ($x);
?>
What will be the output when Mark tries to compile and execute the code?
What does the following code snippet do?
$a = `ls -l`;
John works as a Website Developer for PHPWEB Inc. He is using a Windows operating system and is also working on PHP engine 5.0. He develops the following script:
<?php
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1965));
?>
What will be the output of the above PHP script?
Which of the following types of errors halts the execution of a script and cannot be trapped?
Which of the following features are Undeprecated in PHP 5.3?
Consider the following PHP script:
<html>
<head>
<title>
This is a test script.
</title>
</head>
<body>
<?php
echo (int) ((0.1 + 0.7) * 10);
?>
</body>
</html>
What will be the output of the PHP script?
Which of the following statements explains the difference between print() and echo()?
What is the output of the following PHP code?
<?php
define('FOO', 10);
$array = array(10 => FOO,"FOO" => 20);
print $array[$array[FOO]] * $array["FOO"];
?>
Mark works as a Web Developer for Unicorn Inc. He develops an application in PHP using the following code:
<?php
switch(1) {
case 1: print("Book Details");
case 2: print("Book Author");
default: print("Missing Book");
}
?>
What will be the output of the script?
Consider the following code:
<?php
$x=0;
$i;
for($i=0;$i<5;$i++)
{
$x+=$i;
}
print($x);
?>
What will be the value of x?
Consider the following code:
<?php
function modvalue() {
$a=20;
$b=4;
$c=$a%$b;
print($c);
}
modvalue();
?>
What will be the value of the variable c?
You run the following PHP script:
<?php
function calc() {
$x=10;
$b=++$x;
print($b);
}
calc();
?>
What will be the value of the variable b?
Which of the following are the core extensions?
Each correct answer represents a complete solution. Choose all that apply.
You have been given a code snippet as follows:
$somearray = array("hi", "this is a string", "this is a code");
You want to iterate this array and modify the value of each of its elements. Which of the following is the best possible to accomplish the task?
Which of the following code can be used to create case insensitive constant? (choose 2)
<?php
define("GREETING","How are you today?",TRUE);
echo constant("greeting");
?>
B.
<?php
define("GREETING","How are you today?");
echo constant("greeting");
?>
C.
<?php
define("GREETING","How are you today?",FALSE);
echo constant("greeting");
?>
D.
<?php
define("GREETING","How are you today?",'USECASE');
echo constant("greeting");
?>
You run the following PHP script:
<php
echo 0x33, ' birds sit on ', 022, ' trees.';
?>
What will be the output?
Consider the following code:
<?php
$a;
for($a=1;$a<=100;$a++) {
if($a==50) {
continue;
}
print($a);
}
?>
What will be the output of the program?
In which of the following ways does the identity operator === compare two values?
What is the output of the following code snippet?
<?php
$a = 20;
function myfunction($b) {
$a = 30;
global $a, $c;
return $c = ($b + $a);
}
print myfunction(40) + $c;
?>
Which of the following PHP variable names is not a valid variable name?
Assume that today is January 8th, 2013, 5:16:18 pm in MST time zone.
<?php
echo date('l \t\h\e jS');
?>
What is the value of $x in the following code snippet?
<?php
$x = 123 == 0123;
?>
$a = 1234; // decimal number $a = -123; // a negative number $a = 0123; // octal number (equivalent to 83 decimal) $a = 0x1A; // hexadecimal number (equivalent to 26 decimal) $a = 0b11111111; // binary number (equivalent to 255 decimal)
Which of the following functions returns current Unix timestamp?
Which of the following files can be used to modify PHP configurations?
Which of the following PHP directives will you use to display all errors except notices?
You run the following PHP script:
<?php
$a=12;
$b=11;
$a>$b ? print($a) : print($b);
?>
Which of the following is used to set a constant?
What is the length of the hash generated by the crc32() crypto function?
Which of the following logical operators is an equivalence logical operator?
Which of the following is a magic constant?
Which of the following operators has the highest precedence order?
Which of the following is related to APC (Alternative PHP Cache)?
Which of the following is NOT a strongly typed language?
Which of the following is NOT a valid PHP variable name?
You run the following PHP script:
<?
$a=20%-8;
echo $a;
?>
You run the following PHP script:
<?
echo (int) "1235Jason";
?>
What will be the output?
You run the following script:
<?php
function odd() {
for($i=1; $i<=50; $i=$i+2)
{
echo "$i";
}
}
echo "The last value of the variable \$i: $i";
?>
What will be the output?
You run the following PHP script:
<?
echo (int) "Jason 1235";
?>
What will be the output?
You run the following PHP script:
<?php
$sale = 200;
$sale = $sale- + 1;
echo $sale;
?>
What will be the output?
Which of the following functions allows you to stack several error handlers on top of each other?
Consider the following code:
<?php
function add() {
$x=10;
$y=5;
$x+=$y;
}
?>
What will be the value of x and y?
You run the following PHP script:
<?
$a = "b";
$b = 20;
echo $$a;
?>
What will be the output?
You run the following PHP script:
<?
$a = "b";
$b = 20;
${20} = $a;
echo ${$b};
?>
What will be the output?
You run the following script:
<?
10 = $a;
echo $a;
?>
You run the following PHP script:
<?php
$num = -123test;
$newnum = abs( $num );
print $newnum;
?>
What will be the output?
Which of the following will you use to iterate a PHP associative array?
You run the following script:
<?php
$a = 6 - 10 % 4;
echo $a;
?>
What will be the output?
You run the following script:
<?php
$a=5 < 2;
echo (gettype($a));
?>
What will be the output?
Your application needs to handle file uploads performed with HTTP PUT. How can you retrieve this data?
How can the line on which HTTP headers were sent inside a script be determined?
What is the output of the following code?
$a = 'myVar';
switch($a) {
case 0:
echo 'case 0';
case 'myVar':
echo 'case myVar';
case 'nothing':
echo 'case nothing';
}
Assume that you are using PHP s session management without cookies and want to make sure that session information does not get lost when redirecting the client to another URL. Which of the following functions do you need to achieve that? (Choose 3)
What is the best all-purpose way of comparing two strings?
What will be the net effect of running the following script on the $a string
<?php $s = '<p>Hello</p>'; $ss = htmlentities($s); echo $s; ?>
What is the output of the following code?
print strpos('Zend Certified Engineer', 116);
mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )Important: If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. In this case, 116 is an Ascii code equivalent to "t", position 8 in the string "Zend Certified Engineer".
What is the output of the following PHP script?
<?php
for ($i = 5; ; $i++) {
if ($i < 10) {
break;
}
}
echo $i;
?>
Enter the exact script output
What is the output of the following code?
$a = 1; $b = 2; $c = 3; echo (++$a) + ($b++) + (++$c) + ($a++) + (++$b) + ($c++);
Which PHP extension can you use to connect to HTTP, SMTP or FTP servers?
What is the default timeout of a PHP session cookie?
What is the recommended setting for error_reporting for production
servers?