Zend Certified PHP Engineer

QUESTION NO: 1

What is the output of the following code?

echo '1' . (print '2') + 3;

A. 123

B. 213

C. 142

D. 214

E: Syntax error

Answer: D

QUESTION NO: 2

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;

}

A. one

B. two

C. three

D. four

Answer: C

QUESTION NO: 3

What is "instanceof" an example of?

A. a boolean

B. an operator

C. a function

D. a language construct

E: a class magic

Answer: B

QUESTION NO: 4

Which of the following may be used in conjunction with CASE inside a SWITCH statement?

A. A scalar

B. An expression

C. A boolean

D. All of the above

Answer: D

QUESTION NO: 5

What is the output of the following code?

$a = 'a'; $b = 'b';

echo isset($c) ? $a.$b.$c : ($c = 'c').'d';

A. abc

B. cd

C. 0d

Answer: B

QUESTION NO: 6

Which of the following are valid identifiers? (Choose 3)

A. function 4You() { }

B. function _4You() { }

C. function object() { }

D. $1 = "Hello";

E: $_1 = "Hello World";

Answer: B, C, E

QUESTION NO: 7

What super-global should be used to access information about uploaded files via a POST request?

A. $_SERVER

B. $_ENV

C. $_POST

D. $_FILES

E: $_GET

Answer: D

QUESTION NO: 8

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

Answer: B

QUESTION NO: 9

What is the output of the following code?

echo "1" + 2 * "0x02";

A. 1

B. 3

C. 5

D. 20

E: 7

Answer: C

QUESTION NO: 10

What is the result of the following bitwise operation in PHP?

1 ^ 2

A. 1

B. 3

C. 2

D. 4

E: -1

Answer: B

QUESTION NO: 11

What is the output of the following code?

echo "22" + "0.2", 23 . 1;

A. 220.2231

B. 22.2231

C. 22.2,231

D. 56.2

Answer: B

QUESTION NO: 12

What is the output of the following code?

$first = "second";

$second = "first";

echo $$$first;

A. "first"

B. "second"

C. an empty string

D. an error

Answer: B

QUESTION NO: 13

Your supervisor wants you to disallow PHP scripts to open remote HTTP and FTP resources using PHP's file functions. Which php.ini setting should you change accordingly?

Answer: allow_url_fopen, allow_url_fopen=off, allow_url_fopen=Off, allow_url_fopen = off, allow_url_fopen = Off

QUESTION NO: 14

Which of the following code snippets DO NOT write the exact content of the file "source.txt" to "target.txt"? (Choose 2)

A. file_put_contents("target.txt", fopen("source.txt", "r"));

B. file_put_contents("target.txt", readfile("source.txt"));

C. file_put_contents("target.txt", join(file("source.txt"), "\n"));

D. file_put_contents("target.txt", file_get_contents("source.txt"));

E: $handle = fopen("target.txt", "w+"); fwrite($handle, file_get_contents("source.txt")); fclose($handle);

Answer: B, C

QUESTION NO: 15

What is the recommended method of copying data between two opened files?

A. copy($source_file, $destination_file);

B. copy($destination_file, $source_file);

C. stream_copy_to_stream($source_file, $destination_file);

D. stream_copy_to_stream($destination_file, $source_file);

E: stream_bucket_prepend($source_file, $destination_file);

Answer: C

QUESTION NO: 16

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

Answer: D

QUESTION NO: 17

What function allows resizing of PHP's file write buffer?

A. ob_start()

B. set_write_buffer()

C. stream_set_write_buffer()

D. Change the output_buffering INI setting via ini_set() function

Answer: C

QUESTION NO: 18

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.

Answer: B

QUESTION NO: 19

What can prevent PHP from being able to open a file on the hard drive (Choose 2)?

A. File system permissions

B. File is outside of open_basedir

C. File is inside the /tmp directory.

D. PHP is running in CGI mode.

Answer: A, B

QUESTION NO: 20

What purpose do namespaces fulfill?

A. Encapsulation

B. Alternative to classes

C. Improved performance

D. All of the above

Answer: A

QUESTION NO: 21

When would you use classes and when would you use namespaces?

A. Use classes to encapsulate code and represent objects, and namespaces to avoid symbol name collisions

B. Use classes for performance-sensitive code, and namespaces when readability matters more

C. Use namespaces for performance-sensitive code, and classes when readability matters more

D. Always use them; namespaces are always superior to classes

Answer: A

QUESTION NO: 22

Which of these elements can be encapsulated by namespaces and made accessible from the outside?

A. Only classes

B. Classes, functions and constants

C. Classes, functions, constants and variables

Answer: B

QUESTION NO: 23

You'd like to use the class MyDBConnection that's defined in the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace, but you want to minimize *as much as possible* the length of the class name you have to type. What would you do?

A. Import the MyGreatFramework namespace

B. Import the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace

C. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer\MyDBConnection to a shorter name

D. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer to a shorter name

Answer: C

QUESTION NO: 24

How should you track errors on your production website?

A. Enabling display_errors

B. Enabling log_errors

C. Having a site-wide exception handler

D. Setting error_reporting to E_ALL & ~E_NOTICE

Answer: B

QUESTION NO: 25

What would be the output of the following code?

namespace MyFramework\DB;

class MyClass {

static function myName() {

return __METHOD__;

}

}

print MyClass::myName();

A. MyFramework\DB\myName

B. MyFramework\DB\MyClass\myName

C. MyFramework\DB\MyClass::myName

D. MyClass::myName

Answer: C

QUESTION NO: 26

Which of the following methods are available to limit the amount of resources available to PHP through php.ini? (Choose 2)

A. Limit the amount of memory a script can consume

B. Limit the total amount of memory PHP uses on the entire server

C. Limit the maximum execution time of a script

D. Limit the maximum number of concurrent PHP processes

E: Limit the maximum number of concurrent PHP threads

Answer: A, C

QUESTION NO: 27

Consider the following two files. When you run test.php, what would the output look like?

test.php:

include "MyString.php";

print ",";

print strlen("Hello world!");

MyString.php:

namespace MyFramework\String;

function strlen($str)

{

return \strlen($str)*2; // return double the string length

}

print strlen("Hello world!")

A. 12,12

B. 12,24

C. 24,12

D. 24,24

E: PHP Fatal error: Cannot redeclare strlen()

Answer: C

QUESTION NO: 28

Which line of code can be used to replace the INSERT comment in order to output "hello"?

class C {

public $ello = 'ello';

public $c;

public $m;

function __construct($y) {

$this->c = static function($f) {

// INSERT LINE OF CODE HERE

};

$this->m = function() {

return "h";

};

}

}

$x = new C("h");

$f = $x->c;

echo $f($x->m);

A. return $this->m() . "ello";

B. return $f() . "ello";

C. return "h". $this->ello;

D. return $y . "ello";

Answer: B

QUESTION NO: 29

What is the output of the following code?

function z($x) {

return function ($y) use ($x) {

return str_repeat($y, $x);

};

}

$a = z(2);

$b = z(3);

echo $a(3) . $b(2);

A. 22333

B. 33222

C. 33322

D. 222333

Answer: B

QUESTION NO: 30

What is the output of the following code?

$f = function () { return "hello"; };

echo gettype($f);

A. hello

B. string

C. object

D. function

Answer: C

QUESTION NO: 31

What is the output of the following code?

class C {

public $x = 1;

function __construct() { ++$this->x; }

function __invoke() { return ++$this->x; }

function __toString() { return (string) --$this->x; }

}

$obj = new C();

echo $obj();

A. 0

B. 1

C. 2

D. 3

Answer: D

QUESTION NO: 32

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"

Answer: static

QUESTION NO: 33

Which SPL class implements fixed-size storage?

Answer: SplFixedArray

QUESTION NO: 34

In order to create an object storage where each object would be stored only once, you may use which of the following? (Choose 2)

A. SplFixedArray

B. SplObjectStorage

C. SplString

D. spl_object_hash

E: spl_same_object

Answer: B, D

QUESTION NO: 35

What is the output of the following code?

class Base {

protected static function whoami() {

echo "Base ";

}

public static function whoareyou() {

static::whoami();

}

}

class A extends Base {

public static function test() {

Base::whoareyou();

self::whoareyou();

parent::whoareyou();

A::whoareyou();

static::whoareyou();

}

public static function whoami() {

echo "A ";

}

}

class B extends A {

public static function whoami() {

echo "B ";

}

}

B::test();

A. B B B B B

B. Base A Base A B

C. Base B B A B

D. Base B A A B

Answer: C

QUESTION NO: 36

Late static binding is used in PHP to:

A. Load dynamic libraries and extensions at runtime

B. Use caller class information provided in static method call

C. Resolve undefined class names by automatically including needed files

D. Find proper method to call according to the call arguments

Answer: B

QUESTION NO: 37

What is the output of the following code?

class Test {

public function __call($name, $args)

{

call_user_func_array(array('static', "test$name"), $args);

}

public function testS($l) {

echo "$l,";

}

}

class Test2 extends Test {

public function testS($l) {

echo "$l,$l,";

}

}

$test = new Test2();

$test->S('A');

A. A,

B. A,A,

C. A,A,A,

D. PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback

Answer: B

QUESTION NO: 38

Which of the following tasks can be achieved by using magic methods? (Choose 3)

A. Initializing or uninitializing object data

B. Creating a new stream wrapper

C. Creating an iterable object

D. Processing access to undefined methods or properties

E: Overloading operators like +, *, etc.

F: Converting objects to string representation

Answer: A, D, F

QUESTION NO: 39

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

A. MyObject should extend class Closure

B. MyObject should implement interface Callable

C. MyObject should implement method __call

D. MyObject should implement method __invoke

Answer: D

QUESTION NO: 40

Consider the following code. What change must be made to the class for the code to work as written?

class Magic {

protected $v = array("a" => 1, "b" => 2, "c" => 3);

public function __get($v) {

return $this->v[$v];

}

}

$m = new Magic();

$m->d[] = 4;

echo $m->d[0];

A. Nothing, this code works just fine.

B. Add __set method doing $this->v[$var] = $val

C. Rewrite __get as: public function __get(&$v)

D. Rewrite __get as: public function &__get($v)

E: Make __get method static

Answer: D

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.