Winter Special Flat 65% Limited Time Discount offer - Ends in 0d 00h 00m 00s - Coupon code: netdisc

Zend 200-550 Zend Certified PHP Engineer Exam Practice Test

Page: 1 / 22
Total 223 questions

Zend Certified PHP Engineer Questions and Answers

Testing Engine

  • Product Type: Testing Engine
$42  $119.99

PDF Study Guide

  • Product Type: PDF Study Guide
$36.75  $104.99
Question 1

The constructs for(), foreach(), and each() can all be used to iterate an object if the object...

Options:

A.

implements ArrayAccess

B.

implements Iterator

C.

implements Iterator and ArrayAccess

D.

None of the above

Question 2

What is the output of the following code?

function fibonacci (&$x1 = 0, &$x2 = 1)

{

$result = $x1 + $x2;

$x1 = $x2;

$x2 = $result;

return $result;

}

for ($i = 0; $i < 10; $i++) {

echo fibonacci() . ',';

}

Options:

A.

An error

B.

1,1,1,1,1,1,1,1,1,1,

C.

1,1,2,3,5,8,13,21,34,55,

D.

Nothing

Question 3

Which PHP function sets a cookie and URL encodes its value when sending it to the browser?

Options:

Question 4

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

Options:

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

Question 5

You want to allow your users to submit HTML code in a form, which will then be displayed as real code and not affect your page layout. Which function do you apply to the text, when displaying it? (Choose 2)

Options:

A.

strip_tags()

B.

htmlentities()

C.

htmltidy()

D.

htmlspecialchars()

E.

showhtml()

Question 6

What is the length of a string returned by: md5(rand(), TRUE);

Options:

A.

Depends on the value returned by rand() function

B.

32

C.

24

D.

16

E.

64

Question 7

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

Options:

A.

MIME type

B.

File name extension

C.

Contents of the file

Question 8

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

Options:

A.

false-false

B.

false-true

C.

true-false

D.

true-true

Question 9

Which of the following is correct? (Choose 2)

Options:

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.

Question 10

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

Options:

A.

4

B.

5

C.

8

D.

None of the above

Question 11

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

Options:

A.

PHPIterator

B.

RecursiveTreeIterator

C.

RecursiveDirectoryIterator

D.

SplTempFileObject

Question 12

What will the following code print out?

$str = '✔ one of the following';

echo str_replace('✔', 'Check', $str);

Options:

A.

Check one of the following

B.

one of the following

C.

✔ one of the following

Question 13

When retrieving data from URLs, what are valid ways to make sure all file_get_contents calls send a certain user agent string? (Choose 2)

Options:

A.

$default_opts = array('http'=>array('user_agent'=>"My Cool Browser"));

$default = stream_context_set_default($default_opts);

B.

stream_context_set_option("user_agent", "My Cool Browser");

C.

ini_set('user_agent', "My Cool Browser");

D.

stream_context_set_option($context, "http", "user_agent", "My Cool Browser");

Question 14

Consider the following XML code:

<books>

<book id="1">PHP 5.5 in 42 Hours

<book id="2">Learning PHP 5.5 The Hard Way

Which of the following SimpleXML calls prints the name of the second book?

(Let $xml = simplexml_load_file("books.xml"); .) (Choose 2)

Options:

A.

echo $xml->books->book[2];

B.

echo $xml->books->book[1];

C.

echo $xml->book[1];

D.

echo $xml->xpath("/books/book[@id=2]");

E.

$c = $xml->children(); echo $c[1];

Question 15

What is the output of the following code?

var_dump(boolval([]));

Options:

A.

bool(true)

B.

bool(false)

Question 16

How should class MyObject be defined for the following code to work properly? Assume $array is an array and MyObject is a user-defined class.

$obj = new MyObject();

array_walk($array, $obj);

Options:

A.

MyObject should extend class Closure

B.

MyObject should implement interface Callable

C.

MyObject should implement method __call

D.

MyObject should implement method __invoke

Question 17

An HTML form contains this form element:

<input type="image" name="myImage" src="image.png" />

The user clicks on the image to submit the form. How can you now access the relative coordinates of the mouse click?

Options:

A.

$_FILES['myImage']['x'] and $_FILES['myImage']['y']

B.

$_POST['myImage']['x'] and $_POST['myImage']['y']

C.

$_POST['myImage.x'] and $_POST['myImage.y']

D.

$_POST['myImage_x'] and $_POST['myImage_y']

Question 18

What is the difference between "print" and "echo"?

Options:

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

Question 19

Consider the following code:

$result = $value1 ??? $value2;

Which operator needs to be used instead of ??? so that $result equals $value1 if $value1 evaluates to true, and equals $value2 otherwise? Just state the operator as it would be required in the code.

Options:

Question 20

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

Options:

A.

'Hello, world!'

B.

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

C.

array('Hello, world!')

D.

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

Question 21

Which of the following is an invalid DOM save method?

Options:

A.

save()

B.

saveFile()

C.

saveXML()

D.

saveHTML()

E.

saveHTMLFile()

Question 22

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;

}

Options:

A.

one

B.

two

C.

three

D.

four

Question 23

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

Options:

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

Question 24

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

Options:

A.

application/x-www-form-urlencoded

B.

http/post

C.

text/html

D.

object/multipart-formdata

Question 25

What is the output of the following code?

class Number {

private $v;

private static $sv = 10;

public function __construct($v) { $this->v = $v; }

public function mul() {

return static function ($x) {

return isset($this) ? $this->v*$x : self::$sv*$x;

};

}

}

$one = new Number(1);

$two = new Number(2);

$double = $two->mul();

$x = Closure::bind($double, null, 'Number');

echo $x(5);

Options:

A.

5

B.

10

C.

50

D.

Fatal error

Question 26

What is the output of the following code?

function increment ($val)

{

$_GET['m'] = (int) $_GET['m'] + 1;

}

$_GET['m'] = 1;

echo $_GET['m'];

Options:

Question 27

What method can be used to find the tag via the DOM extension?

Options:

A.

getElementById()

B.

getElementsByTagName()

C.

getElementsByTagNameNS()

D.

getElementByName()

E.

findTag()

Question 28

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

Options:

Question 29

Which options do you have in PHP to set the expiry date of a session?

Options:

A.

Set the session.duration directive in php.ini

B.

Set session cookie expiry date locally via session_set_cookie_params()

C.

Set session expiry date locally via session_cache_expire()

D.

None of the above

Question 30

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

Options:

A.

$date2 > $date1

B.

$date2 < $date1

C.

$date1->diff($date2) < 0

D.

$date1->diff($date2) > 0

Question 31

Which one of the following XML declarations is NOT valid?

Options:

A.

B.

C.

D.

Question 32

Which technique should be used to speed up joins without changing their results?

Options:

A.

Add indices on joined columns

B.

Add a WHERE clause

C.

Add a LIMIT clause

D.

Use an inner join

Question 33

Please provide the value of the $code variable in the following statement to set an HTTP status code that signifies that the requested resource was not found.

http_response_code($code);

Options:

Page: 1 / 22
Total 223 questions