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';
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Which of the following functions will allow identifying unique values inside an array?
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Which of the following parts must a XML document have in order to be well-formed?
-
A
-
B
-
C
-
D
A reference to either a DTD or an XML schema definition
Reveal answer details
Close answer details
Question 4
Fill in the blank
FILL BLANK What is the output of the following code? function increment ($val) { $val = $val + 1; } $val = 1; increment ($val); echo $val;
Reveal answer details
Close answer details
What is the output of the following code? echo "22" + "0.2", 23 . 1;
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
An object can be counted with count() and sizeof() if it...
-
A
-
B
has a public__count() method
-
C
was cast to an object from an array
-
D
Reveal answer details
Close answer details
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);
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
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());
-
A
Fatal error: Access to private variable MyTrait::$abc from context MyClass
-
B
Notice: Undefined property MyClass::$abc
-
C
-
D
-
E
Reveal answer details
Close answer details
What would be the output of the following code? namespace MyFramework\DB; class MyClass { static function myName() { return __METHOD__; } } print MyClass::myName();
-
A
-
B
MyFramework\DB\MyClass\myName
-
C
MyFramework\DB\MyClass::myName
-
D
Reveal answer details
Close answer details
Question 10
Multiple choice
Which of the following is correct? (Choose 2)
-
A
A class can extend more than one class.
-
B
A class can implement more than one class.
-
C
A class can extend more than one interface.
-
D
A class can implement more than one interface.
-
E
An interface can extend more than one interface.
-
F
An interface can implement more than one interface.
Reveal answer details
Close answer details
Question 11
Single choice
Which of these statements about PDO is NOT true?
-
A
PDO has built-in support for Large Objects (LOBs).
-
B
Placeholders within PDO prepared statements need to be named.
-
C
When something goes wrong, PDO can throw an instance of its own exception class.
-
D
PDO does not emulate missing database features.
Reveal answer details
Close answer details
Question 12
Single choice
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 [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] 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', '[email protected]'); $stmt->execute(); echo "Success!"; } catch (PDOException $e) { echo "Failure!"; throw $e; }
-
A
The INSERT will succeed and the user will see the "Success!" message.
-
B
The INSERT will fail because of a primary key violation, and the user will see the "Success!" message.
-
C
The INSERT will fail because of a primary key violation, and the user will see a PDO warning message.
-
D
The INSERT will fail because of a primary key violation, and the user will see the "Failure!" message.
Reveal answer details
Close answer details
Question 13
Multiple choice
Which of the following are NOT acceptable ways to create a secure password hash in PHP? (Choose 2)
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Question 14
Multiple choice
In a shared hosting environment, session data can be read by PHP scripts written by any user. How can you prevent this? (Choose 2)
-
A
Store session data in a different location with session.save_path .
-
B
Store session data in a database.
-
C
-
D
Set session.name to something unique.
Reveal answer details
Close answer details
Question 15
Fill in the blank
FILL BLANK Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP?
Reveal answer details
Close answer details
Accepted answerAnswer: is_uploaded_file(), is_uploaded_file
Question 16
Single choice
Which of the following expressions will evaluate to a random value from an array below? $array = array("Sue","Mary","John","Anna");
-
A
-
B
-
C
-
D
$array[array_rand($array)];
-
E
array_values($array, ARRAY_RANDOM);
Reveal answer details
Close answer details
Question 17
Single choice
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; }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 18
Single choice
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());
-
A
No changes needed, the code would output 2 as is
-
B
Line A, to: protected &$x = array();
-
C
Line B, to: public function &getX() {
-
D
Line C, to: return &$this->x;
-
E
Line D, to: $a =& new A();
Reveal answer details
Close answer details
Question 19
Single choice
What is the output of the following code? var_dump(boolval([]));
-
A
-
B
Reveal answer details
Close answer details
Question 20
Single choice
Which of the following statements is true?
-
A
All PHP database extensions support prepared statements
-
B
All PHP database extensions come with their own special helper functions to escape user data to be used in dynamic SQL queries
-
C
All PHP database extensions provide an OOP interface
-
D
All PHP database extensions appear in the output of php -m , if installed and enabled
Reveal answer details
Close answer details
Question 21
Multiple choice
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)
-
A
echo $xml->books->book[2];
-
B
echo $xml->books->book[1];
-
C
-
D
echo $xml->xpath("/books/book[@id=2]");
-
E
$c = $xml->children(); echo $c[1];
Reveal answer details
Close answer details
Question 22
Single choice
From your PHP application, how can you send the same header twice, but with different values?
-
A
Set the second argument of the header() function to false
-
B
PHP does that automatically
-
C
You may only send a particular type of header once
-
D
Use the header_add() function
Reveal answer details
Close answer details
Question 23
Single choice
The constructs for(), foreach(), and each() can all be used to iterate an object if the object...
-
A
-
B
-
C
implements Iterator and ArrayAccess
-
D
Reveal answer details
Close answer details
Question 24
Single choice
Which class of HTTP status codes is used for redirections?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 25
Single choice
What is the output of the following code? class a { public $val; } function renderVal (a $a) { if ($a) { echo $a->val; } } renderVal (null);
-
A
A syntax error in the function declaration line
-
B
An error, because null is not an instance of 'a'
-
C
Nothing, because a null value is being passed to renderVal()
-
D
Reveal answer details
Close answer details
Question 26
Multiple choice
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)
-
A
-
B
The transaction affected no lines
-
C
The transaction was rolled back
-
D
The transaction was committed without error
Reveal answer details
Close answer details
Question 27
Single choice
What is the output of the following code? for ($i = 0; $i < 1.02; $i += 0.17) { $a[$i] = $i; } echo count($a);
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Question 28
Single choice
Which one of the following XML declarations is NOT valid?
-
A
-
B
<?xml version="1.1" encoding="UTF-8" ?>
-
C
-
D
Reveal answer details
Close answer details
Question 29
Fill in the blank
FILL BLANK Which value will be assigned to the key 0 in this example? $foo = array(true, '0' => false, false => true);
Reveal answer details
Close answer details
Accepted answerAnswer: true
Question 30
Single choice
How can a SimpleXML object be converted to a DOM object?
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Question 31
Single choice
Before the headers are sent, how can you remove a previously set header?
-
A
Use the header_remove() function, providing the name of the header
-
B
Use the die() function to abort the PHP script
-
C
-
D
Use the headers_list() function, providing the name of the header as the second argument
Reveal answer details
Close answer details
Question 32
Single choice
Which of the following statements is NOT true?
-
A
Class constants are public
-
B
Class constants are being inherited
-
C
Class constants can omit initialization (default to NULL)
-
D
Class constants can be initialized by const
Reveal answer details
Close answer details
Question 33
Single choice
After performing the following operations: $a = array('a', 'b', 'c'); $a = array_keys(array_flip($a)); What will be the value of $a?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 34
Single choice
What is the output of the following code? var_dump(boolval(-1));
-
A
-
B
Reveal answer details
Close answer details
|