Zend Certified PHP Engineer

QUESTION NO: 41

SimpleXML provides the ability to iterate over items in an XML document, as well as access items within it as if they were object properties. When creating your own classes to access data, implementing which of the following would NOT achieve this goal?

A. __toString

B. Iterator

C. __get/__set

D. ArrayAccess

Answer: A

QUESTION NO: 42

Which of the following is used to find all PHP files under a certain directory?

A. PHPIterator

B. RecursiveTreeIterator

C. RecursiveDirectoryIterator

D. SplTempFileObject

Answer: C

QUESTION NO: 43

Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP?

Answer: is_uploaded_file(), is_uploaded_file

QUESTION NO: 44

Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP, and also save the contents into another folder?

Answer: move_uploaded_file(), move_uploaded_file

QUESTION NO: 45

What is the name of the key for the element in $_FILES['name'] that contains the provisional name of the uploaded file?

Answer: tmp_name

QUESTION NO: 46

What is the name of the key in $_FILES['name'] that contains the number of bytes of the uploaded file?

Answer: size

QUESTION NO: 47

What information can be used to reliably determine the type of an uploaded file?

A. MIME type

B. File name extension

C. Contents of the file

Answer: C

QUESTION NO: 48

Which MIME type is always sent by a client if a JPEG file is uploaded via HTTP?

A. image/jpeg

B. image/jpg

C. image/pjpeg

D. Depends on the client system

Answer: D

QUESTION NO: 49

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)

A. The PHP configuration option post_max_size is set to a value that is too small

B. The web server is using an incorrect encoding as part of the HTTP response sent to the client

C. The browser uses an incorrect encoding as part of the HTTP request sent to the server

D. The hidden form field MAX_FILE_SIZE was set to a value that is too small

E: PHP cannot process file uploads larger than 4 MB

Answer: A, D

QUESTION NO: 50

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);

A. The database will return no rows.

B. The value of $row will be an array.

C. The value of $result will be empty.

D. The value of $result will be 'gamma@example.net'.

Answer: D

QUESTION NO: 51

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.

Answer: B

QUESTION NO: 52

Consider the following table data and PHP code. What is a possible 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 name, email FROM users LIMIT 1";

$stmt = $pdo->prepare($cmd);

$stmt->execute();

$result = $stmt->fetchAll(PDO::FETCH_BOTH);

$row = $result[0];

A. The value of $row is `array(0 => 'anna', 1 => 'alpha@example.com')`.

B. The value of $row is `array('name' => 'anna', 'email' => 'alpha@example.com')`.

C. The value of $row is `array(0 => 'anna', 'name' => 'anna', 1 => 'alpha@example.com', 'email' => 'alpha@example.com')`.

D. The value of $result is `array('anna' => 'alpha@example.com')`.

Answer: C

QUESTION NO: 53

Consider the following table data and PHP code, and assume that the database supports transactions. 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 {

$pdo->exec("INSERT INTO users (id, name, email) VALUES (6, 'bill', 'delta@example.com')");

$pdo->begin();

$pdo->exec("INSERT INTO users (id, name, email) VALUES (7, 'john', 'epsilon@example.com')");

throw new Exception();

} catch (Exception $e) {

$pdo->rollBack();

}

A. The user 'bill' will be inserted, but the user 'john' will not be.

B. Both user 'bill' and user 'john' will be inserted.

C. Neither user 'bill' nor user 'john' will be inserted.

D. The user 'bill' will not be inserted, but the user 'john' will be.

Answer: A

QUESTION NO: 54

Given a PHP value, which sample shows how to convert the value to JSON?

A. $string = json_encode($value);

B. $string = Json::encode($value);

C. $json = new Json($value); $string = $json->__toString();

D. $value = (object) $value; $string = $value->__toJson();

Answer: A

QUESTION NO: 55

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);

Answer: C

QUESTION NO: 56

Which of the following PHP values may NOT be encoded to a JavaScript literal using PHP's ext/json capabilities?

A. 'Hello, world!'

B. function(){ alert("Hello, world!"); }

C. array('Hello, world!')

D. array('message' => 'Hello, world!')

Answer: B

QUESTION NO: 57

Which of the following will NOT instantiate a DateTime object with the current timestamp?

A. $date = new DateTime();

B. $date = new DateTime('@' . time());

C. $date = new DateTime('now');

D. $date = new DateTime(time());

Answer: D

QUESTION NO: 58

Given a DateTime object that is set to the first second of the year 2014, which of the following samples will correctly return a date in the format '2014-01-01 00:00:01'?

A. $datetime->format('%Y-%m-%d %h:%i:%s')

B. $datetime->format('%Y-%m-%d %h:%i:%s', array('year', 'month', 'day', 'hour', 'minute', 'second'))

C. $datetime->format('Y-m-d H:i:s')

D. $date = date('Y-m-d H:i:s', $datetime);

Answer: C

QUESTION NO: 59

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');

A. $date2 > $date1

B. $date2 < $date1

C. $date1->diff($date2) < 0

D. $date1->diff($date2) > 0

Answer: A

QUESTION NO: 60

Given the following DateTime object, which sample will NOT alter the date to the value '2014-02-15'?

$date = new DateTime('2014-03-15');

A. $date->sub(new DateInterval('P1M'));

B. $date->setDate(2014, 2, 15);

C. $date->modify('-1 month');

D. $date->diff(new DateInterval('-P1M'));

Answer: D

QUESTION NO: 61

Which interfaces could class C implement in order to allow each statement in the following code to work? (Choose 2)

$obj = new C();

foreach ($obj as $x => $y) {

echo $x, $y;

}

A. Iterator

B. ArrayAccess

C. IteratorAggregate

D. ArrayObject

Answer: A, C

QUESTION NO: 62

What is the output of the following code?

class Foo Implements ArrayAccess {

function offsetExists($k) { return true;}

function offsetGet($k) {return 'a';}

function offsetSet($k, $v) {}

function offsetUnset($k) {}

}

$x = new Foo();

echo array_key_exists('foo', $x)?'true':'false';

A. true

B. false

Answer: B

QUESTION NO: 63

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

Answer: B

QUESTION NO: 64

What is the output of the following code?

$a = array('a', 'b'=>'c');

echo property_exists((object) $a, 'a')?'true':'false';

echo '-';

echo property_exists((object) $a, 'b')?'true':'false';

A. false-false

B. false-true

C. true-false

D. true-true

Answer: B

QUESTION NO: 65

Assuming UTF-8 encoding, what is the value of $count?

$data = '$1ā2';

$count = strlen($data);

A. 0

B. 4

C. 5

D. 7

Answer: C

QUESTION NO: 66

What is the output of this code?

$world = 'world';

echo <<<'TEXT'

hello $world

TEXT;

A. hello world

B. hello $world

C. PHP Parser error

Answer: C

QUESTION NO: 67

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 '&#9986;&#10004;&#10013;';

A. Three Unicode characters, or unreadable text, depending on the browser

B. &#9986;&#10004;&#10013;

C. A blank line due to charset mismatch

Answer: A

QUESTION NO: 68

What will the following code print out?

$str = '&#10004; one of the following';

echo str_replace('&#10004;', 'Check', $str);

A. Check one of the following

B. one of the following

C. &#10004; one of the following

Answer: A

QUESTION NO: 69

What is the pattern modifier for handling UTF-8 encoded preg_* functionality?

A. e

B. u

C. PHP does not support UTF-8 encoded strings

D. A pattern modifier is not needed

Answer: B

QUESTION NO: 70

What is the output of the following code?

$text = 'This is text';

$text1 = <<<'TEXT'

$text

TEXT;

$text2 = <<<TEXT

$text1

TEXT;

echo "$text2";

A. This is text

B. $text

C. $text1

D. $text2

Answer: B

QUESTION NO: 71

Your public web application needs to provide access to binary files for registered users only. How would you achieve this?

A. Host the files on a public external file sharing service.

B. Redirect to the file which resides in the server's document root

C. Use PHP to send the file to the client, using the header() function to set appropriate HTTP headers

D. PHP is used for service HTML content, not binary content

Answer: C

QUESTION NO: 72

What content-type is required when sending an HTTP POST using JavaScript to ensure that PHP can access the data?

A. application/x-www-form-urlencoded

B. http/post

C. text/html

D. object/multipart-formdata

Answer: A

QUESTION NO: 73

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

Answer: A

QUESTION NO: 74

Which class of HTTP status codes is used for server error conditions?

A. 2XX

B. 3XX

C. 4XX

D. 5XX

Answer: D

QUESTION NO: 75

Which class of HTTP status codes is used for redirections?

A. 2XX

B. 3XX

C. 4XX

D. 5XX

Answer: B

QUESTION NO: 76

Which of the following can NOT be used to send a cookie from within a PHP application?

A. header()

B. $_COOKIE

C. setcookie()

D. setrawcookie()

Answer: B

QUESTION NO: 77

Under what condition may HTTP headers be set from PHP if there is content echoed prior to the header function being used?

A. headers_sent() returns true

B. Output buffering is enabled

C. The client supports local buffering

D. The webserver uses preemptive mode

Answer: B

QUESTION NO: 78

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. Not possible

D. Use the headers_list() function, providing the name of the header as the second argument

Answer: A

QUESTION NO: 79

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

Answer: C

QUESTION NO: 80

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.

Answer: D

QUESTION NO: 81

What is the output of the following code?

function append($str)

{

$str = $str.'append';

}

function prepend(&$str)

{

$str = 'prepend'.$str;

}

$string = 'zce';

append(prepend($string));

echo $string;

A. zceappend

B. prependzceappend

C. prependzce

D. zce

Answer: C

Site Search:

Close

Close
Download Free Demo of VCE
Exam Simulator

Experience Avanset VCE Exam Simulator for yourself.


Simply submit your e-mail address below to get started with our interactive software demo of your free trial.


Enter Your Email Address

Free Demo Limits: In the demo version you will be able to access only first 5 questions from exam.