Summer Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: exc65

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"

How can you determine whether a PHP script has already sent cookies to the client?

A.

Use $_COOKIE

B.

Use the getcookie() function

C.

Use the headers_sent() function

D.

Use JavaScript to send a second HTTP request

What is the return value of the following code: substr_compare("foobar", "bar", 3);

A.

-1

B.

1

C.

TRUE

D.

0

E.

FALSE

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.

What is "instanceof" an example of?

A.

a boolean

B.

an operator

C.

a function

D.

a language construct

E.

a class magic

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.

NULL

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;

}

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 is the name of the function that allows you register a set of functions that implement user-defined session handling?

A.

session_set_handler()

B.

session_set_storage_handler()

C.

session_register_handler()

D.

session_set_save_handler()

An HTML form contains this form element:

When this form is submitted, the following PHP code gets executed:

move_uploaded_file(

$_FILES['myFile']['tmp_name'],

'uploads/' . $_FILES['myFile']['name']

);

Which of the following actions must be taken before this code may go into production? (Choose 2)

A.

Check with is_uploaded_file() whether the uploaded file $_FILES['myFile']['tmp_name'] is valid

B.

Sanitize the file name in $_FILES['myFile']['name'] because this value is not consistent among web browsers

C.

Check the charset encoding of the HTTP request to see whether it matches the encoding of the uploaded file

D.

Sanitize the file name in $_FILES['myFile']['name'] because this value could be forged

E.

Use $HTTP_POST_FILES instead of $_FILES to maintain upwards compatibility

An HTML form has two submit buttons. After submitting the form, how can you determine with PHP which button was clicked?

A.

An HTML form may only have one button.

B.

You cannot determine this with PHP only. You must use JavaScript to add a value to the URL depending on which button has been clicked.

C.

Put the two buttons in different forms, but make sure they have the same name.

D.

Assign name and value attributes to each button and use $_GET or $_POST to find out which button has been clicked.