What will the following code print out?
$str = '✔ one of the following';
echo str_replace('✔', 'Check', $str);
From your PHP application, how can you send the same header twice, but with different values?
Which parts of the text are matched in the following regular expression?
$text = << The big bang bonged under the bung. EOT; preg_match_all('@b.n?g@', $text, $matches);
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);
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?
echo '1' . (print '2') + 3;
What DOMElement method should be used to check for availability of a non-namespaced attribute?
Which of these elements can be encapsulated by namespaces and made accessible from the outside?
What is cached by an opcode cache?
Which is the most efficient way to determine if a key is present in an array, assuming the array has no NULL values?
What is the output of this code?
$world = 'world';
echo <<<'TEXT'
hello $world
TEXT;
Which of the following is NOT true about PHP traits? (Choose 2)
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);
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);
Which of the following statements about SOAP is NOT true?
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 SimpleXML function is used to parse a file?
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)
An unbuffered database query will: (Choose 2)
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 a SimpleXML object be converted to a DOM object?
Which of the following statements about anonymous functions in PHP are NOT true? (Choose 2)
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');
Which MIME type is always sent by a client if a JPEG file is uploaded via HTTP?
Which of the following expressions will evaluate to a random value from an array below?
$array = array("Sue","Mary","John","Anna");
What is the name of the key in $_FILES['name'] that contains the number of bytes of the uploaded file?
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?
$first = "second";
$second = "first";
echo $$$first;
What is the result of the following bitwise operation in PHP?
1 ^ 2
Which constant must be passed as the second argument to htmlentities() to convert single quotes (') to HTML entities?
What is the result of the following code?
class T
{
const A = 42 + 1;
}
echo T::A;
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 { }
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)