3 Months Free Update
3 Months Free Update
3 Months Free Update
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);
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);
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.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);
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();
}
What is the output of the following code?
echo 0x33, ' monkeys sit on ', 011, ' trees.';
Please provide the name of the super-global variable where all the information about cookies is available.
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');
PHP's array functions such as array_values() can be used on an object if the object...
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;
}
How can the id attribute of the 2nd baz element from the XML string below be retrieved from the SimpleXML object
found inside $xml?
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 result of the following code?
define('PI', 3.14);
class T
{
const PI = PI;
}
class Math
{
const PI = T::PI;
}
echo Math::PI;
How can you determine whether a PHP script has already sent cookies to the client?
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 superglobals does not necessarily contain data from the client?
What will the following code print out?
$str = '✔ one of the following';
echo str_replace('✔', 'Check', $str);
Which of the following items in the $_SERVER superglobal are important for authenticating the client when using HTTP Basic authentication? (Choose 2)
Which of the following code snippets DO NOT write the exact content of the file "source.txt" to "target.txt"? (Choose 2)
Which PHP function sets a cookie whose value does not get URL encoded when sending it to the browser?
What is the output of the following code?
function ratio ($x1 = 10, $x2)
{
if (isset ($x2)) {
return $x2 / $x1;
}
}
echo ratio (0);
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 content-type is required when sending an HTTP POST using JavaScript to ensure that PHP can access the data?
The following form is loaded in a browser and submitted, with the checkbox activated:
In the server-side PHP code to deal with the form data, what is the value of $_POST['accept'] ?
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);
When using password_hash() with the PASSWORD_DEFAULT algorithm constant, which of the following is true? (Choose 2)
What is the result of the following code?
class T
{
const A = 42 + 1;
}
echo T::A;
What is the return value of the following code?
strpos("me myself and I", "m", 2)
Under what condition may HTTP headers be set from PHP if there is content echoed prior to the header function being used?
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)
Which of the following tasks can be achieved by using magic methods? (Choose 3)
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"
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 DOMElement method should be used to check for availability of a non-namespaced attribute?
Which technique should be used to speed up joins without changing their results?
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);
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);
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;
}
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)
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 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 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?
When a browser requests an image identified by an img tag, it never sends a Cookie header.
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?
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);
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);