Given a php.ini setting of
default_charset = utf-8
what will the following code print in the browser?
header('Content-Type: text/html; charset=iso-8859-1');
echo 'and#9986;and#10004;and#10013;';
A. Three Unicode characters, or unreadable text, depending on the browser
B. and#9986;and#10004;and#10013;
C. A blank line due to charset mismatch
What is the difference between "print" and "echo"?
A. There is no difference.
B. Print has a return value, echo does not
C. Echo has a return value, print does not
D. Print buffers the output, while echo does not
E. None of the above
What is "instanceof" an example of?
A. a boolean
B. an operator
C. a function
D. a language construct
E. a class magic
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.
What parsing methodology is utilized by the SimpleXML extension?
A. SAX
B. DOM
C. XPath
D. Push/Pull Approach
E. Expat
What does the __FILE__ constant contain?
A. The filename of the current script.
B. The full path to the current script.
C. The URL of the request made.
D. The path to the main script.
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?
A. header()
B. headers()
C. headers_list()
D. headers_sent()
E. getresponseheaders()
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. false-false
B. false-true
C. true-false
D. true-true
What is the preferred method for preventing SQL injection?
A. Always using prepared statements for all SQL queries.
B. Always using the available database-specific escaping functionality on all variables prior to building the SQL query.
C. Using addslashes() to escape variables to be used in a query.
D. Using htmlspecialchars() and the available database-specific escaping functionality to escape variables to be used in a query.