Zend PHP5 Certification Mock Exam Sample Questions — 3
Hi 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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
<!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>
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) {
}
?>
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)
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)
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)
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)
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)
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)
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)
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 <<a href=»http://example.org/»>http://www.example.org/</a>.>
<br/>
</p>
</body>
</html>
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)
<!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;
?>
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>
http://en.wikipedia.org/wiki/XML-RPC
137. Which of the following functions are part of PHP's internal Iterator interface? (Choose 5 answers)
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)
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)
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)
Link?
141. When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for? (Choose 1 answer)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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);
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)
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)
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)
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)
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)
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)
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)
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)
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)
http://php.net/manual/en/language.operators.arithmetic.php
169. What is the output of the following? (Choose 1 answer)
http://php.net/manual/en/language.references.pass.php
170. What is the output of the following? (Choose 1 answer)
http://php.net/manual/en/language.references.pass.php
171. What is the output of the following? (Choose 1 answer)
http://www.php.net/manual/en/functions.returning-values.php, so INT(null)*6=0.
- textual
- unicode
- numeric
- binary
- constant
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)
- PRAGMA locking_mode = «Row»;
- PRAGMA count_changes = Off;
- PRAGMA default_synchronous = Off;
- PRAGMA default_synchronous = On;
- PRAGMA locking_mode = «Table»;
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");
}
?>
- mysqli_connect_error();
- mysqli_connect_error($link);
- mysqli_error();
- $_MySQL['connect_error']
- mysqli_get_connect_error();
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));
}
?>
- A transaction must be begun and the variables must be assigned
- Each value must be assigned prior to calling mysqli_bind_param(), and thus nothing should be done
- Use mysqli_bind_value() to assign each of the values
- Assign $myinteger, $mydouble, $myblob, $myvarchar the proper values
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";
}
?>
- None of the above
- mysqli_fetch_columns($first, $last, $phone);
- mysqli_stmt_bind_result($statement, $first, $last, $phone);
- A while loop, fetching the row and assigning $first, $last, and $phone the proper value
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)
- Updating a single row in a table
- Inserting a new row into a single table
- Performing a stored procedure
- Selecting rows from multiple different tables
- Updating a single row in multiple different tables
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)
- SAX
- FastDOM
- DOM
- XPath
- XML to Object mapping
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)
- All of the above are valid
- mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
- oci:dbname=//localhost:1521/mydb
- mysql:host=localhost;port=3307;dbname=testdb
- sqlite2:/opt/databases/mydb.sq2
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)
- wrap the PDO DSN in a try/catch block to catch any connection exception
- Use constants in the PDO DSN
- Place the login credentials in the php.ini file
- Disable E_STRICT and E_NOTICE error reporting levels
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) {
/* ??????? */
}
/* ?????? */
?>
- $dbh->beginTransaction();
- $dbh->commit();
- $stmt->execute();
- $dbh->rollback();
- $dbh->query($stmt);
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)
- Extending the PDOStatement Class
- Set the PDO::ATTR_STATEMENT_CLASS parameter
- Call the PDO::setStatementClass() method
- Extend the PDO class
- Set the PDO::ATTR_USE_CLASS paramater
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)
- Disabling of the short_tags PHP.ini directive
- Enabling the asp_tags PHP.ini directive
- That you have XPath support enabled in PHP 5
- That your XML documents are well-formed
- None of the above, PHP can be embedded in XML in all cases.
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)
- Validators
- DTD
- Transformations
- Namespaces
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>
- The document is completely valid
- All special XML characters must be represented as entities within the content of a node
- All tags must be closed
- You cannot specify a namespace for the <html> attribute
- The DOCTYPE declaration is malformed
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)
- SAX
- DOM
- XML Object Mapping
- XPath
- XQuery
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 <<a href=»http://example.org/»>http://www.example.org/</a>.>
<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) {
}
?>
- xml_set_callback(«xml_start_handler»);
- xml_set_element_handler($xml, «xml_start_handler», «xml_end_handler»);
- xml_node_set_handler(«xml_start_handler», «xml_end_handler»);
- xml_node_set_handler(«xml_start_handler»);
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)
- All of the above
- Faster then DOM methods
- Requires less memory then DOM
- Easier to develop parsers
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";
?>
- Displays the content of every <body> node
- Displays the «background» attribute for the first node in the XML document named «body»
- Displays the content of every node that has a «background» node
- Displays the «background» attribute of every node named «body»
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)
- XQuery
- XPath
- SimpleXML
- DOM
- SAX
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";
?>
- «*[local-name()='body']«
- «/body[0]/text»
- «/body/body[0]«
- «name='body'»
- «*[lname()='body']«
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);
?>
- $dom->createTextNode(„Hello, World“);
- $dom->appendElement($title, „text“, „Hello, world!“);
- $dom->appendTextNode($title, „Hello, World!“);
- $dom->createElement('text', „Hello, World“);
- None of the above
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)
- Element namespaces are denoted by the 'namespace' attribute
- converting an element to a string denotes text data
- Non-numeric indexes are element attributes
- Numeric indexes are elements
- Properties denote element iterators
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)
- A String
- An array
- A DomDocument object
- A URI
- A Database resource
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 <<a href=»http://example.org/»>http://www.example.org/</a>.>
<br/>
</p>
</body>
</html>
- $sxe->body->p[0]->a[1]['href']
- $sxe->body->p->a->href
- $sxe->body->p->a['href']
- $sxe['body']['p'][0]['a']['href']
- $sxe->body->p[1]->a['href']
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;
?>
- trim(($p[1]));
- trim(strip_tags(($p->asText())));
- trim(strip_tags(($p->asXML())));
- trim(($p->asXML()));
- strip_tags(($p->asXML()));
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>
- None of the above
- A fragment of a complete SOAP request
- XML-RPC
- REST
- SOAP
http://en.wikipedia.org/wiki/XML-RPC
137. Which of the following functions are part of PHP's internal Iterator interface? (Choose 5 answers)
- rewind()
- valid()
- next()
- key()
- current()
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";
}
}
}
}
?>
- None of the above
- The XML of each 'title' node
- The XML of each 'item' node
- «Title» for every title node in the document
- The contents of every 'title' node which exists under an 'item' node
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)
- fetchColumn()
- fetchObject()
- fetch()
- fetchClass()
- fetchRow()
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)
- performance first, maintainability second
- Maintainability first, performance second
- Maintainability
- Performance
Link?
141. When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for? (Choose 1 answer)
- None of the above
- Ensuring that all columns are of a particular case when fetched
- Adjusting the case of a query before it is processed for compatibility reasons
- Controls the switch logic of how queries are processed
- Allows you to adjust the memory cache (or «case») for increased performance
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;
}
?>
- $info[1] is the database-specific error code
- $info[2] is the database-specific error message
- $info[1] is the unified error code
- $info[0] is the unified error code
- $info[0] Is the Database-specific error message
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)
- get_backtrace()
- get_function_stack()
- debug_backtrace()
- debug_print_backtrace()
- print_backtrace()
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)
- Moving all database credentials into a single file
- Moving all database credentials outside of the document root
- Restricting access to files not designed to be executed independently
- Setting credential information as system environment variables
- Using PHP constants instead of variables to store credentials
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)
- Sessions on shared hosts are easily hijacked by outside malicious users
- All of the above
- You cannot use a custom data store in shared hosts
- Session data stored in the file system can be read by other scripts on the same shared host
- Users outside the shared host can access any site which created a session for them
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)
- Switch
- Conditional
- Goto
- Call
- Dynamic
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)
- They are always seek-able
- When used properly they significantly reduce memory consumption
- They can be applied to any data source
- They are always bi-directional
- They can be filtered
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)
- When running in a Linux environment local filesystem
- When accessing the stream of the local filesystem
- When running in a Windows environment and accessing a share
- When accessing a bi-directional stream
- When accessing a read-only stream
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);
?>
- The request is blocking and may cause fread() to hang
- The HTTP request is malformed
- This script should be re-written using fgets() instead of fread()
- The request is non-blocking and fread() may miss the response
- You cannot use fwrite() with fsockopen()
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)
- Buffered
- Buckets
- Wrappers
- Filters
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)
- b
- x
- a
- w
- r+
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)
- STDIN
- __STDIN__
- STDIO
- PHP::STDIO
- STD_IN
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);
?>
- gzip://foo.gz?level=9
- compress.zip://foo.gz?level=9
- compress.zlib://foo.gz
- compress.gzip://foo.gz?level=9
- zlib://foo.gz
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)
- ftps://
- ftp://
- sftp://
- https://
- http://
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)
- Provide a context for fopen() using stream_context_create()
- You must delete the file first before uploading a new file
- Configure this behavior in the php.ini file using the ftp.overwrite directive
- Open the file using the 'w+' mode
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)
- stream_get_blocking
- stream_get_meta_data
- stream_is_blocking
- stream_get_blocking_mode
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)
- Require constructs can't be used with URL filenames
- Include constructs cause a fatal error if the file doesn't exist
- There is no difference other than the name
- Include constructs are processed at run time; require constructs are processed at compile time
- Require constructs cause a fatal error if the file can't be read
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)
- Use stdin(), stdout() and stderr() functions
- PHP::STDIN, PHP::STDOUT, PHP::STDERR class constants in PHP 5
- STDIN, STDOUT, and STDERR constants in PHP 5
- use the php::stdin(), php::stdout(), and php::stderr() class methods
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);
- Use flock_lazy() instead of flock()
- Use LOCK_EX|LOCK_NB instead of LOCK_EX
- Use LOCK_UN instead of LOCK_EX
- Check the value of $retval to see if the lock was obtained
- Check to see if $retval == LOCK_WAIT
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;
- 2
- 4
- 5
- 10
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)
- $argv[3];
- $argv[2];
- func_get_args(3);
- func_get_arg(2);
- func_get_arg(3);
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++;
- 16
- 51
- 15
- 6
- 5
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);
- Bartlet
- Anjo
- BartletAnjo
- AnjoBartlet
- None / There is an Error
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)
- Always; objects are passed by reference in PHP5
- When the calling code preceeds the variable name with a &
- Never; objects are cloned when passed to a function
- When the function paramater listing preceeds the variable name with 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();
?>
- No output or error. Variables can not be optional and passed by reference.
- 5
- 6
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;
?>
- Error: Unexpected T_VARIABLE
- 10
- Notice regarding pass by reference
- 50
- 5
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);
?>
- …0
- Parse Error: Syntax Error
- …
- …
- …
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);
?>
- ##
- Notice
- Warning
- Syntax Error
- #
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;
?>
- 50
- 5
- 95
- 10
- 100
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";
?>
- I have 6 apples and 6 oranges
- I have 6 apples and 5 oranges
- I have 5 apples and 6 oranges
- I have 5 apples and 5 oranges
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);
?>
- 0
- 36
- 6
- 30
- 5
http://www.php.net/manual/en/functions.returning-values.php, so INT(null)*6=0.
No comments:
Post a Comment