Which of the following will set a 10 seconds read timeout for a stream?
A. ini_set("default_socket_timeout", 10);
B. stream_read_timeout($stream, 10);
C. Specify the timeout as the 5th parameter to the fsockopen() function used to open a stream
D. stream_set_timeout($stream, 10);
E. None of the above
Which of the following is used to find all PHP files under a certain directory?
A. PHPIterator
B. RecursiveTreeIterator
C. RecursiveDirectoryIterator
D. SplTempFileObject
Given a JSON-encoded string, which code sample correctly indicates how to decode the string to native PHP values?
A. $json = new Json($jsonValue); $value = $json->decode();
B. $value = Json::decode($jsonValue);
C. $value = json_decode($jsonValue);
D. $value = Json::fromJson($jsonValue);
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";
}
}
A. Rename the A::hello() method to a different name using A::hello as helloA;
B. Use B::hello() instead of A 's version using B::hello insteadof A
C. Use B::hello() instead of A 's version using use B::hello
D. Rename the A::hello() method to a different name using A::hello renameto helloA;
E. None of the above (both can be used directly)
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);
A. No, the code is fully protected from SQL Injection.
B. Yes, because the $name variable is improperly escaped.
C. Yes, because the $name variable and the $age variable is improperly escaped.
D. Yes, because the $age variable is improperly escaped.
E. Yes, because you cannot prevent SQL Injection when using MySQLi
Which of the following items in the $_SERVER superglobal are important for authenticating the client when using HTTP Basic authentication? (Choose 2)
A. PHP_AUTH_TYPE
B. PHP_AUTH_PASSWORD
C. PHP_AUTH_DIGEST
D. PHP_AUTH_PW
E. PHP_AUTH_USER
Which of the following superglobals does not necessarily contain data from the client?
A. $_POST
B. $_SESSION
C. $_GET
D. $_SERVER
You need to escape special characters to use user input inside a regular expression. Which functions would you use? (Choose 2)
A. addslashes()
B. htmlentities()
C. preg_quote()
D. regex_quote()
E. quote_meta()
What is the return value of the following code?
strpos("me myself and I", "m", 2)
A. 2
B. 3
C. 4
D. 0
E. 1