Zend PHP5 Certification Mock Exam Sample Questions — 3

zend logoHi friends, I decided to post on his blog the exam questions to test Zend PHP5 with the correct (imho) answers and explain their references.

If you have additions or questions please write them in the comments.

111. Unlike a database such as MySQL, SQLite columns are not explicitly typed. Instead, SQLite catagorizes data into which of the following catagories? (Choose 2 answers)

  1. textual
  2. unicode
  3. numeric
  4. binary
  5. constant

Answer: A, C
http://www.sqlite.org/datatype3.html: the database engine may convert values between numeric storage classes (INTEGER and REAL) and TEXT during query execution.

112. Which of the following SQL statements will improve SQLite write performance? (Choose 2 answers)

  1. PRAGMA locking_mode = «Row»;
  2. PRAGMA count_changes = Off;
  3. PRAGMA default_synchronous = Off;
  4. PRAGMA default_synchronous = On;
  5. PRAGMA locking_mode = «Table»;

Answer: B, C
http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#pragmas

113. Consider the following code snippet. What would go in place of the ???? above for this script to function properly? (Choose 1 answer)
<?php
$link = mysqli_connect("hostname","username","password");
if(!$link)
{
   $error = ??????
   die("Could not connect to the database: $error");
}
?>

  1. mysqli_connect_error();
  2. mysqli_connect_error($link);
  3. mysqli_error();
  4. $_MySQL['connect_error']
  5. mysqli_get_connect_error();

Answer: A
http://php.net/manual/ru/mysqli.connect-error.php — Returns a string description of the last connect error

114. Consider the following code snippet. Assuming this snippet is a smaller part of a correctly written script, what actions must occur in place of the ????? in the above code snippet to insert a row with the following values: 10, 20.2, foo, string? (Choose 1 answer)
<?php
$query = "INSERT INTO mytable
(myinteger, mydouble, myblob, myvarchar)
VALUES (?, ?, ?, ?)";
$statement = mysqli_prepare($link, $query);
if(!$statement)
{
   die(mysqli_error($link));
}
/* The variables being bound to by MySQLi
don't need to exist prior to binding */
mysqli_bind_param($statement, "idbs",
$myinteger, $mydouble, $myblob, $myvarchar);
/* ???????????? */
/* execute the query, using the variables as defined. */
if(!mysqli_execute($statement))
{
   die(mysqli_error($link));
}
?>

  1. A transaction must be begun and the variables must be assigned
  2. Each value must be assigned prior to calling mysqli_bind_param(), and thus nothing should be done
  3. Use mysqli_bind_value() to assign each of the values
  4. Assign $myinteger, $mydouble, $myblob, $myvarchar the proper values

Answer: D
http://www.php.net/manual/en/mysqli-stmt.bind-param.php: Example #2 Procedural style, http://php.net/manual/ru/mysqli.prepare.php: The parameter markers must be bound to application variables using mysqli_stmt_bind_param() and/or mysqli_stmt_bind_result()before executing the statement or fetching rows, also mysqli_bind_value is not exists in php.net.

115. Consider the following code snippet, assuming this code snippet is part of a larger correct application, what must be done in place of the ???? above for the correct output to be displayed? (Choose 1 answer)
<?php
$query = "SELECT first, last, phone FROM contacts WHERE first LIKE 'John%'";
$statement = mysqli_prepare($link, $query);
mysqli_execute($statement);
/* ???? */
while(($result = mysqli_stmt_fetch($statement)))
{
   print "Name: $first $last\n";
   print "Phone: $phone\n\n";
}
?>

  1. None of the above
  2. mysqli_fetch_columns($first, $last, $phone);
  3. mysqli_stmt_bind_result($statement, $first, $last, $phone);
  4. A while loop, fetching the row and assigning $first, $last, and $phone the proper value

Answer: C
http://ru.php.net/manual/en/mysqli-stmt.bind-result.php — Binds variables to a prepared statement for result storage.

116. Which of the following cases are cases when you should use transactions? (Choose 1 answer)

  1. Updating a single row in a table
  2. Inserting a new row into a single table
  3. Performing a stored procedure
  4. Selecting rows from multiple different tables
  5. Updating a single row in multiple different tables

Answer: E
http://php.net/manual/en/pdo.transactions.php – Example #6 Executing a batch in a transaction

117. PHP 5 supports which of the following XML parsing methods? (Choose 4 answers)

  1. SAX
  2. FastDOM
  3. DOM
  4. XPath
  5. XML to Object mapping

Answer: A, C, D, E
http://pear.php.net/package/XML_HTMLSax, http://php.net/manual/de/book.dom.php, http://php.net/manual/de/simplexmlelement.xpath.php, http://www.php.net/manual/en/function.simplexml-load-file.php (Interprets an XML file into an object) and FastDOM is not exists.

118. Which of the following is not a valid PDO DSN? (Choose 1 answer)

  1. All of the above are valid
  2. mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
  3. oci:dbname=//localhost:1521/mydb
  4. mysql:host=localhost;port=3307;dbname=testdb
  5. sqlite2:/opt/databases/mydb.sq2

Answer: A
all from http://php.net/manual/en/pdo.drivers.php: http://www.php.net/manual/en/ref.pdo-mysql.connection.php (Example #1 PDO_MYSQL DSN examples), http://www.php.net/manual/en/ref.pdo-oci.connection.php (Example #1 PDO_OCI DSN examples), http://www.php.net/manual/en/ref.pdo-sqlite.connection.php (Example #1 PDO_SQLITE DSN examples)

119. When connecting to a database using PDO, what must be done to ensure that database credentials are not compromised if the connection were to fail? (Choose 1 answer)

  1. wrap the PDO DSN in a try/catch block to catch any connection exception
  2. Use constants in the PDO DSN
  3. Place the login credentials in the php.ini file
  4. Disable E_STRICT and E_NOTICE error reporting levels

Answer: A
http://www.php.net/manual/en/pdo.connections.php: Example #3 Handling connection errors, If your application does not catch the exception thrown from the PDO constructor, the default action taken by the zend engine is to terminate the script and display a back trace. This back trace will likely reveal the full database connection details, including the username and password. It is your responsibility to catch this exception, either explicitly (via acatch statement) or implicitly via set_exception_handler().

120. Consider the following script. What lines of code need to go into the missing places above in order for this script to function properly and insert the data into the database safely? (Choose 4 answers)
<?php
try {
   $dbh = new PDO("sqlite::memory:");
} catch(PDOException $e) {
   print $e->getMessage();
}
$dbh->query("CREATE TABLE foo(id INT)");
$stmt = $dbh->prepare("INSERT INTO foo VALUES(:value)");
$value = null;
$data = array(1,2,3,4,5);
$stmt->bindParam(":value", $value);
/* ?????? */
try {
   foreach($data as $value) {
/* ????? */
}
} catch(PDOException $e) {
/* ??????? */
}
/* ?????? */
?>

  1. $dbh->beginTransaction();
  2. $dbh->commit();
  3. $stmt->execute();
  4. $dbh->rollback();
  5. $dbh->query($stmt);

Answer: A, C, D, B
http://www.php.net/manual/en/pdo.query.php: For a query that you need to issue multiple times, you will realize better performance if you prepare a PDOStatement object using PDO::prepare() and issue the statement with multiple calls to PDOStatement::execute().

121. Implementing your own PDO class requires which steps from the list below? (Choose 3 answers)

  1. Extending the PDOStatement Class
  2. Set the PDO::ATTR_STATEMENT_CLASS parameter
  3. Call the PDO::setStatementClass() method
  4. Extend the PDO class
  5. Set the PDO::ATTR_USE_CLASS paramater

Answer: D, A, B
http://php.net/manual/en/book.pdo.php

122. When embedding PHP into XML documents, what must you ensure is true in order for things to function properly? (Choose 1 answer)

  1. Disabling of the short_tags PHP.ini directive
  2. Enabling the asp_tags PHP.ini directive
  3. That you have XPath support enabled in PHP 5
  4. That your XML documents are well-formed
  5. None of the above, PHP can be embedded in XML in all cases.

Answer: D
http://www.daaq.net/old/php/index.php?page=embedding+php&parent=php+basics: “… This means that XML documents containing PHP should still be well-formed and valid.”, and about well-formed xml from IBM.

123. What XML technology is used when you mix two different document types in a single XML document? (Choose 1 answer)

  1. Validators
  2. DTD
  3. Transformations
  4. Namespaces

Answer: D (B)
http://www.webdeveloper.com/forum/showthread.php?t=230532: ultimately DTD or Namespaces?

124. Consider the following example XML document. What is wrong with this document, and how can it be corrected? (Choose 2 answers)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML Example</title>
</head>
<body>
<p>
Moved to <<a href="http://example.org/">http://www.example.org/</a>.>
<br>
</p>
</body>
</html>

  1. The document is completely valid
  2. All special XML characters must be represented as entities within the content of a node
  3. All tags must be closed
  4. You cannot specify a namespace for the <html> attribute
  5. The DOCTYPE declaration is malformed

Answer: B, C
http://en.wikipedia.org/wiki/Well-formed_element for <br>, http://en.wikipedia.org/wiki/XML#Escaping for node content ‘Moved to <<a href=»http://example.org/»>http://www.example.org/</a>.>’

125. Event-based XML parsing is an example of which parsing model? (Choose 1 answer)

  1. SAX
  2. DOM
  3. XML Object Mapping
  4. XPath
  5. XQuery

Answer: A
http://en.wikipedia.org/wiki/Simple_API_for_XML#XML_processing_with_SAX: A parser which implements SAX (ie, a SAX Parser) functions as a stream parser, with an event-driven API. The user defines a number of callback methods that will be called when events occur during parsing.

126. Consider the following code segment. What should be placed in place of ?????? above to have the above script display the name of each tag within the XML document? (Choose 1 answer)
<?php
$xmldata = <<< XML
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE html
PUBLIC «-//W3C//DTD XHTML 1.0 Transitional//EN»
«http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd»>
<html xmlns=»http://www.w3.org/1999/xhtml» xml:lang=»en» lang=»en»>
<head>
<title>XML Example</title>
</head>
<body>
<p>
Moved to &lt;<a href=»http://example.org/»>http://www.example.org/</a>.&gt;
<br/>
</p>
</body>
</html>
XML;

$xml = xml_parser_create(«UTF-8»);

/* ??????? */

xml_parse($xml, $xmldata);

function xml_start_handler($xml, $tag, $attributes) {
print «Tag: $tag<br/>\n»;
}

function xml_end_handler($xml, $tag) {
}
?>

  1. xml_set_callback(«xml_start_handler»);
  2. xml_set_element_handler($xml, «xml_start_handler», «xml_end_handler»);
  3. xml_node_set_handler(«xml_start_handler», «xml_end_handler»);
  4. xml_node_set_handler(«xml_start_handler»);

Answer: B
http://php.net/manual/en/function.xml-set-element-handler.php – Set up start and end element handlers.

127. What is the primary benefit of a SAX-based XML parser compared to DOM? (Choose 1 answer)

  1. All of the above
  2. Faster then DOM methods
  3. Requires less memory then DOM
  4. Easier to develop parsers

Answer: A
http://en.wikipedia.org/wiki/Simple_API_for_XML#Benefits and D because B & C is strongly right.

128. What does the following PHP script accomplish? (Choose 1 answer)
<?php
$dom = new DomDocument();
$dom->load('test.xml');
$body = $dom->documentElement->getElementsByTagName('body')->item(0);
echo $body->getAttributeNode('background')->value. "\n";
?>

  1. Displays the content of every <body> node
  2. Displays the «background» attribute for the first node in the XML document named «body»
  3. Displays the content of every node that has a «background» node
  4. Displays the «background» attribute of every node named «body»

Answer: B
http://ru2.php.net/manual/en/function.domdocument-get-elements-by-tagname.php – Returns array with nodes with given tagname in document or empty array, if not found

129. Creating new nodes in XML documents using PHP can be done using which XML/PHP 5 technologies? (Choose 2 answers)

  1. XQuery
  2. XPath
  3. SimpleXML
  4. DOM
  5. SAX

Answer: C, D
http://php.net/manual/en/class.simplexmlelement.php – public SimpleXMLElement addChild, http://php.net/manual/en/domdocument.createelement.php

130. Consider the following simple PHP script. What XPath query should go in the ?????? above to display the «bgcolor» attribute of the first «body» node in the XML document? (Choose 1 answer)
<?php
$dom = new DomDocument();
$dom->load('test.xml');
$xpath = new DomXPath($dom);
$nodes = $xpath->query(???????, $dom->documentElement);
echo $nodes->item(0)->getAttributeNode('bgcolor')->value
. "\n";
?>

  1. «*[local-name()='body']«
  2. «/body[0]/text»
  3. «/body/body[0]«
  4. «name='body'»
  5. «*[lname()='body']«

Answer: A
http://www.w3.org/TR/xpath/#function-local-name – returns the local part of the expanded-name of the node in the argument node-set that is first in document order.

131. Consider the following PHP script fragment. What should ??????? be replaced with to add a <title> node with the value of Hello, World! (Choose 1 answer)
<?php
$title = $dom->createElement('title');
$node = ????????
$title->appendChild($node);
$head->appendChild($title);
?>

  1. $dom->createTextNode(„Hello, World“);
  2. $dom->appendElement($title, „text“, „Hello, world!“);
  3. $dom->appendTextNode($title, „Hello, World!“);
  4. $dom->createElement('text', „Hello, World“);
  5. None of the above

Answer: E
As for me its could be options A (http://php.net/manual/ru/domdocument.createtextnode.php) and В (http://php.net/manual/ru/domdocument.createelement.php) but in both exclamation mark is missed.

132. When working with SimpleXML in PHP 5, the four basic rules on how the XML document is accessed are which of the following? (Choose 4 answers)

  1. Element namespaces are denoted by the 'namespace' attribute
  2. converting an element to a string denotes text data
  3. Non-numeric indexes are element attributes
  4. Numeric indexes are elements
  5. Properties denote element iterators

Answer: B, C, D, E
Because http://docs.php.net/manual/en/simplexmlelement.getnamespaces.php namespaces are denoted by the ‘xmlns’ attribute.

133. SimpleXML objects can be created from what types of data sources? (Choose 3 answers)

  1. A String
  2. An array
  3. A DomDocument object
  4. A URI
  5. A Database resource

Answer: A, C, D
http://php.net/manual/en/simplexmlelement.construct.php — (Data: A well-formed XML string or the path or URL to an XML document if data_is_url is TRUE.) Example #2 Create a SimpleXMLElement object from a URL.

simplexml_import_dom — Get a SimpleXMLElement object from a DOM node,
simplexml_load_string — Interprets a string of XML into an object

134. Given the following XML document in a SimpleXML object. Select the proper statement below which will display the HREF attribute of the anchor tag. (Choose 1 answer)
<?xml version=»1.0" encoding=»ISO-8859-1" ?>
<!DOCTYPE html
PUBLIC «-//W3C//DTD XHTML 1.0 Transitional//EN»
«http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd»>
<html xmlns=»http://www.w3.org/1999/xhtml» xml:lang=»en» lang=»en»>
<head>
<title>XML Example</title>
</head>
<body>
<p>
Moved to &lt;<a href=»http://example.org/»>http://www.example.org/</a>.&gt;
<br/>
</p>
</body>
</html>

  1. $sxe->body->p[0]->a[1]['href']
  2. $sxe->body->p->a->href
  3. $sxe->body->p->a['href']
  4. $sxe['body']['p'][0]['a']['href']
  5. $sxe->body->p[1]->a['href']

Answer: C
http://www.php.net/manual/en/simplexml.examples-basic.php: Example #5 Using attributes.

With p[0] is also working but without a[1]['href'].

135. Given the following PHP script. What should go in place of ????? above to print the string ‘Hello, World!’ (with no leading/trailing whitespace or markup)? (Choose 1 answer)
<?php
$xmldata = <<< XML
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE html
PUBLIC «-//W3C//DTD XHTML 1.0 Transitional//EN»
«http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd»>
<html xmlns=»http://www.w3.org/1999/xhtml» xml:lang=»en» lang=»en»>
<head>
<title>XML Example</title>
</head>
<body>
<p>
<b>Hello, World!</b>
</p>
</body>
</html>
XML;
$sxe = simplexml_load_string($xmldata);
$p = $sxe->body->p;
$string = ????????
print $string;
?>

  1. trim(($p[1]));
  2. trim(strip_tags(($p->asText())));
  3. trim(strip_tags(($p->asXML())));
  4. trim(($p->asXML()));
  5. strip_tags(($p->asXML()));

Answer: C
http://php.net/manual/ru/simplexmlelement.asxml.php and also SimpleXMLElement::asText() is not exists

136. The following is a common XML structure used in service oriented architectures, what does it represent? (Choose 1 answer)
<?xml version=»1.0"?>
<methodCall>
<methodName>myMethod</methodName>
<params>
<param>
<value><string>HI!</string></value>
</param>
</params>
</methodCall>

  1. None of the above
  2. A fragment of a complete SOAP request
  3. XML-RPC
  4. REST
  5. SOAP

Answer: C
http://en.wikipedia.org/wiki/XML-RPC

137. Which of the following functions are part of PHP's internal Iterator interface? (Choose 5 answers)

  1. rewind()
  2. valid()
  3. next()
  4. key()
  5. current()

Answer: ALL
http://php.net/manual/en/class.iterator.php

138. Consider the following script. Assuming the referenced XML document exists and matches the parsing logic, what should be displayed when this script is executed? (Choose 1 answer)
<?php
$dom = new DOMDOcument();
$dom->load("myxmlfile.xml");
foreach($dom->documentElement->childNodes as $child)
{
   if(($child->nodeType == XML_ELEMENT_NODE) && $child->nodeName == "item")
   {
      foreach($child->childNodes as $item)
      {
         if(($item->nodeType == XML_ELEMENT_NODE) && ($item->nodeName == "title"))
         {
            print "$item->firstChild->data\n";
         }
      }
   }
}
?>

  1. None of the above
  2. The XML of each 'title' node
  3. The XML of each 'item' node
  4. «Title» for every title node in the document
  5. The contents of every 'title' node which exists under an 'item' node

Answer: E
http://php.net/manual/en/function.domnode-node-type.php

139. Which of the following methods are used to fetch data from a PDO Statement? (Choose 3 answers)

  1. fetchColumn()
  2. fetchObject()
  3. fetch()
  4. fetchClass()
  5. fetchRow()

Answer: A, B, C
http://php.net/manual/en/pdostatement.fetch.php

140. In a general sense, which is more important: performance or maintainability of an application? (Choose 1 answer)

  1. performance first, maintainability second
  2. Maintainability first, performance second
  3. Maintainability
  4. Performance

Answer: B
Link?

141. When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for? (Choose 1 answer)

  1. None of the above
  2. Ensuring that all columns are of a particular case when fetched
  3. Adjusting the case of a query before it is processed for compatibility reasons
  4. Controls the switch logic of how queries are processed
  5. Allows you to adjust the memory cache (or «case») for increased performance

Answer: C
http://php.net/manual/en/pdo.setattribute.php — PDO::ATTR_CASE: Force column names to a specific case.

142. Consider the following PHP code segment, which attempts to execute a PDO query.
In the event of a PDOException, $info is set with the contents of the $errorInfo property of the exception. Which of the following are accurate descriptions of the contents?
(Choose 3 answers)
<?php
try {
$dbh->exec($sql);
} catch (PDOException $e) {
// display warning message
$info = $e->errorInfo;
}
?>

  1. $info[1] is the database-specific error code
  2. $info[2] is the database-specific error message
  3. $info[1] is the unified error code
  4. $info[0] is the unified error code
  5. $info[0] Is the Database-specific error message

Answer: A, B, D
http://www.php.net/manual/en/pdo.errorinfo.php: 0 – SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard), 1 – Driver-specific error code, 2 – Driver-specific error message.

143. Which of the following functions allow you to introspect the call stack during execution of a PHP script? (Choose 2 answers)

  1. get_backtrace()
  2. get_function_stack()
  3. debug_backtrace()
  4. debug_print_backtrace()
  5. print_backtrace()

Answer: C, D
http://php.net/manual-lookup.php?pattern=backtrace=en

144. When working with a database, which of the following can be used to mitigate the possibility of exposing your database credentials to a malicious user? (Choose 3 answers)

  1. Moving all database credentials into a single file
  2. Moving all database credentials outside of the document root
  3. Restricting access to files not designed to be executed independently
  4. Setting credential information as system environment variables
  5. Using PHP constants instead of variables to store credentials

Answer: B, C, D
Links? Some thoughts from zend forum.

145. When running PHP in a shared host environment, what is the major security concern when it comes to session data? (Choose 1 answer)

  1. Sessions on shared hosts are easily hijacked by outside malicious users
  2. All of the above
  3. You cannot use a custom data store in shared hosts
  4. Session data stored in the file system can be read by other scripts on the same shared host
  5. Users outside the shared host can access any site which created a session for them

Answer: D
http://phpsec.org/projects/guide/5.html: “By default, PHP stores session data in /tmp, and this is true for everyone.” — And /tmp is readable for every account on that host.

146. Which of the following are examples of the new engine executor models available in PHP 5? (Choose 3 answers)

  1. Switch
  2. Conditional
  3. Goto
  4. Call
  5. Dynamic

Answer: A, C, D
http://sebastian-bergmann.de/archives/504-PHP-5.1-Performance.html: the new three execution models CALL, GOTO, SWITCH (also from ZDZ)

147. Which of the following are not true about streams? (Choose 2 answers)

  1. They are always seek-able
  2. When used properly they significantly reduce memory consumption
  3. They can be applied to any data source
  4. They are always bi-directional
  5. They can be filtered

Answer: A, D
http://www.php.net/manual/en/streamwrapper.stream-seek.php: If not implemented, FALSE is assumed as the return value. — This would indicate that stream_seek provides no guarantee of usage. Also http://ru.php.net/manual/en/function.stream-get-meta-data.php shown seek-able stream or not. http://php.net/manual/ru/function.popen.php — may be bi-directional but not always.

148. Using flock() to lock a stream is only assured to work under what circumstances? (Choose 1 answer)

  1. When running in a Linux environment local filesystem
  2. When accessing the stream of the local filesystem
  3. When running in a Windows environment and accessing a share
  4. When accessing a bi-directional stream
  5. When accessing a read-only stream

Answer: B
http://php.net/manual/en/function.flock.php: flock() allows you to perform a simple reader/writer model which can be used on virtually every platform (including most Unix derivatives and even Windows).
Note:
May only be used on file pointers returned by fopen() for local files, or file pointers pointing to userspace streams that implement the streamWrapper::stream_lock() method.

149. What is wrong with the following code snippet? Assume default configuration values apply. (Choose 1 answer)
<?php
$fp = fsockopen('www.php.net', 80);
fwrite($fp, "GET / HTTP/1.0\r\nHost: www.php.net\r\n");
$data = fread($fp, 8192);
?>

  1. The request is blocking and may cause fread() to hang
  2. The HTTP request is malformed
  3. This script should be re-written using fgets() instead of fread()
  4. The request is non-blocking and fread() may miss the response
  5. You cannot use fwrite() with fsockopen()

Answer:
http://php.net/manual/en/function.fsockopen.php: Example #1 fsockopen() Example – the request is missing its closing \r\n and as such is malformed.

150. _______ can be used to add additional functionality to a stream, such as implementation of a specific protocol on top of a normal PHP stream implementation. (Choose 1 answer)

  1. Buffered
  2. Buckets
  3. Wrappers
  4. Filters

Answer: C
http://php.net/manual/en/intro.stream.php – A wrapper is additional code which tells the stream how to handle specific protocols/encodings.

151. Which of the following is not a valid fopen() access mode: (Choose 1 answer)

  1. b
  2. x
  3. a
  4. w
  5. r+

Answer: A
http://php.net/manual/en/function.fopen.php – there is no ‘b’ access mode.

152. The _______ constant in a CLI script is an automatically provided file resource representing standard input of the terminal. (Choose 1 answer)

  1. STDIN
  2. __STDIN__
  3. STDIO
  4. PHP::STDIO
  5. STD_IN

Answer: A
http://php.net/manual/en/wrappers.php.php

153. What should go in the ??????? assignment below to create a Zlib-compressed file foo.gz with a compression level of 9? (Choose 1 answer)
<?php
$file = '????????';
$fr = fopen($file, 'wb9');
fwrite($fr, $data);
fclose($fr);
?>

  1. gzip://foo.gz?level=9
  2. compress.zip://foo.gz?level=9
  3. compress.zlib://foo.gz
  4. compress.gzip://foo.gz?level=9
  5. zlib://foo.gz

Answer: C
http://php.net/manual/ru/wrappers.compression.php

154. Which of the following is not a valid default stream wrapper for PHP 5, assuming OpenSSL is enabled? (Choose 1 answer)

  1. ftps://
  2. ftp://
  3. sftp://
  4. https://
  5. http://

Answer: C
http://www.php.net/manual/en/wrappers.php: FTP and FTPS — Accessing FTP(s) URLs.

155. When opening a file in writing mode using the FTP handler, what must be done so that the file will still be written to the server in the event it previously exists? (Choose 1 answer)

  1. Provide a context for fopen() using stream_context_create()
  2. You must delete the file first before uploading a new file
  3. Configure this behavior in the php.ini file using the ftp.overwrite directive
  4. Open the file using the 'w+' mode

Answer: A
http://php.net/manual/en/context.ftp.php:
// Allows overwriting of existing files on the remote FTP server
$stream_options = array('ftp' => array('overwrite' => true));
// Creates a stream context resource with the defined options
$stream_context = stream_context_create($stream_options);
// Opens the file for writing and truncates it to zero length
if ($fh = fopen($ftp_path, 'w', 0, $stream_context))
http://php.net/manual/en/function.stream-context-create.php

156. Which of the following functions is used to determine if a given stream is blocking or not? (Choose 1 answer)

  1. stream_get_blocking
  2. stream_get_meta_data
  3. stream_is_blocking
  4. stream_get_blocking_mode

Answer: B
http://php.net/manual/ru/function.stream-get-meta-data.php

157. What is the difference between the include and require language constructs? (Choose 1 answer)

  1. Require constructs can't be used with URL filenames
  2. Include constructs cause a fatal error if the file doesn't exist
  3. There is no difference other than the name
  4. Include constructs are processed at run time; require constructs are processed at compile time
  5. Require constructs cause a fatal error if the file can't be read

Answer: E
http://php.net/manual/en/function.require.php

158. When writing CLI scripts it is often useful to access the standard streams available to the operating system such as standard input/output and error. How does one access these streams in PHP 5? (Choose 1 answer)

  1. Use stdin(), stdout() and stderr() functions
  2. PHP::STDIN, PHP::STDOUT, PHP::STDERR class constants in PHP 5
  3. STDIN, STDOUT, and STDERR constants in PHP 5
  4. use the php::stdin(), php::stdout(), and php::stderr() class methods

Answer: C
http://php.net/manual/en/wrappers.php.php

159. How can one take advantage of the time waiting for a lock during a stream access, to do other tasks using the following locking code as the base: (Choose 1 answer)
$retval = flock($fr, LOCK_EX);

  1. Use flock_lazy() instead of flock()
  2. Use LOCK_EX|LOCK_NB instead of LOCK_EX
  3. Use LOCK_UN instead of LOCK_EX
  4. Check the value of $retval to see if the lock was obtained
  5. Check to see if $retval == LOCK_WAIT

Answer: B
http://php.net/manual/en/function.flock.php: It is also possible to add LOCK_NB as a bitmask to one of the above operations if you don't want flock() to block while locking. (not supported on Windows).

160. What is the output of? (Choose 1 answer)
function apple($apples = 4)
{
   $apples = $apples / 2;
   return $apples;
}
$apples = 10;
apple($apples);
echo $apples;

  1. 2
  2. 4
  3. 5
  4. 10

Answer: D
http://www.php.net/manual/en/functions.returning-values.php

161. Which statement will return the third parameter passed to a function? (Choose 1 answer)

  1. $argv[3];
  2. $argv[2];
  3. func_get_args(3);
  4. func_get_arg(2);
  5. func_get_arg(3);

Answer: D
http://php.net/manual/en/function.func-get-arg.php — Function arguments are counted starting from zero.

162. What is the output of the following code? (Choose 1 answer)
function oranges(&$oranges = 17)
{
   $oranges .= 1;
}
$apples = 5;
oranges($apples);
echo $apples++;

  1. 16
  2. 51
  3. 15
  4. 6
  5. 5

Answer: B
http://www.php.net/manual/en/functions.arguments.php: Example #2 Passing function parameters by reference, http://php.net/manual/en/language.operators.increment.php: $a++ — Post-increment — Returns $a, then increments $a by one.

163. What is the output of the following code? (Choose 1 answer)
function pears(Array $pears)
{
   if (count($pears) > 0)
   {
      echo array_pop($pears);
      pears($pears);
   }
}
$fruit = array("Anjo", "Bartlet");
pears($fruit);

  1. Bartlet
  2. Anjo
  3. BartletAnjo
  4. AnjoBartlet
  5. None / There is an Error

Answer: C
http://php.net/manual/en/function.array-pop.php

164. In PHP5 objects are passed by reference to a function when (Select the answer that is the most correct): (Choose 1 answer)

  1. Always; objects are passed by reference in PHP5
  2. When the calling code preceeds the variable name with a &
  3. Never; objects are cloned when passed to a function
  4. When the function paramater listing preceeds the variable name with a &

Answer: A
http://php.net/manual/en/language.oop5.references.php — One of the key-points of PHP5 OOP that is often mentioned is that «objects are passed by references by default».

165. What is the output of the following code? (Choose 1 answer)
<?php
function byReference(&$variable = 5)
{
   echo ++$variable;
}
byReference();
?>

  1. No output or error. Variables can not be optional and passed by reference.
  2. 5
  3. 6

Answer: C
http://php.net/manual/en/language.operators.increment.php: ++$a — Pre-increment — Increments $a by one, then returns $a.

166. What is the output of the following code? (Choose 1 answer)
<?php
function x10(&$number)
$number *= 10;
$count = 5;
x10($count);
echo $count;
?>

  1. Error: Unexpected T_VARIABLE
  2. 10
  3. Notice regarding pass by reference
  4. 50
  5. 5

Answer: A
http://www.tizag.com/phpT/phpfunctions.php — curly braces define where our function's code goes.

167. What is the output of the following? (Choose 1 answer)
<?php
function 1dotEach($n)
{
if ($n > 0)
{
   1dotEach(--$n);
   echo ".";
}
else
{
   return $n;
}
}
1dotEach(4);
?>

  1. …0
  2. Parse Error: Syntax Error

Answer: B
http://www.tizag.com/phpT/phpfunctions.php: function name can start with a letter or underscore «_», but not a number!

168. When your error reporting level includes E_STRICT, what will the output of the following code be? (Choose 1 answer)
<?php
function optionalParam($x = 1, $y = 5, $z)
{
if ((!$z > 0))
{
$z = 1;
}
for($count = $x; $count < $y; $count+= $z)
{
echo "#";
}
}
optionalParam(2,4,2);
?>

  1. ##
  2. Notice
  3. Warning
  4. Syntax Error
  5. #

Answer: E
http://php.net/manual/en/language.operators.arithmetic.php

169. What is the output of the following? (Choose 1 answer)
<?php
function byRef(&$number)
{
$number *= 10;
return ($number - 5);
}
$number = 10;
$number = byRef($number);
echo $number;
?>

  1. 50
  2. 5
  3. 95
  4. 10
  5. 100

Answer: C
http://php.net/manual/en/language.references.pass.php

170. What is the output of the following? (Choose 1 answer)
<?php
function byRef(&$apples)
{
   $apples++;
}
$oranges = 5;
$apples = 5;
byRef($oranges);
echo "I have $apples apples and $oranges oranges";
?>

  1. I have 6 apples and 6 oranges
  2. I have 6 apples and 5 oranges
  3. I have 5 apples and 6 oranges
  4. I have 5 apples and 5 oranges

Answer: C
http://php.net/manual/en/language.references.pass.php

171. What is the output of the following? (Choose 1 answer)
<?php
function a($number)
{
   return (b($number) * $number);
}
function b(&$number)
{
   ++$number;
}
echo a(5);
?>

  1. 0
  2. 36
  3. 6
  4. 30
  5. 5
Answer: A
http://www.php.net/manual/en/functions.returning-values.php, so INT(null)*6=0.

Комментариев: 4

  • 16.03.2012 Ollier:

    Hello,

    Congratulation for your web site.

    You published the exam questions to test Zend PHP5 with the correct answers.

    Could you send me those examns in Excel Format or Word format?

    Regards and have a nice day.

  • 15.06.2012 zoho:

    thanks i'm gonna pass that exam...so let me know how should i you this mock exam...they will ask the same questions or what?

    thanks again for your helpful.

    sincerely didierzoho

  • 19.09.2012 serggr:

    123 — D Разбор вопроса тут www.webdeveloper.com/foru...one-XML-document


Добавление комментария:

 css.php