zend php 5 certification practice test 1 « life of miz
DESCRIPTION
Zend PHP 5 Certification Practice Test 1 « Life of MizTRANSCRIPT
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
1/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
Life of Miz
train of thoughts
Zend PHP 5 Certification Practice Test 1
I do not think I’m perfect however if you spot a mistake do let me know.
These are mock exam questions for Zend PHP5 certification. I’ve posted it here so that others canpractice and learn for the exam.
more will be posted soon…
Q1. The following could be better represented as as what?
<?php
if($a == 0) {
}elseif($a == 20) {
}elseif ($a == 30) {
}?>
Answera) A switch statement without break statementb) A foreach statement
c) A while statementd) A switch statemente) Multiple if statements
My Ans: (d)
Q2. The _________ keyword is used to indicate an incomplete class or method, which mustbe further extended and/or implemented in order to be used
Answer:
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
2/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
a) finalb) protected
c) incompleted) abstracte) implements
My Ans: (d)
Q3. The _________ method in PDOStatement class is used to return the next result set in
multi-query statement.
My Ans: (nextRowSet)
Q4. What is the output of this code
<?php$array = array(0.001 => 'b', .1 => 'c')
print_r($array)
?>
Answer:a) An empty arrayb) 0.001 => ‘b’, .1 => ‘c’c) 0 => ‘c’d) ’0.001′ => ‘b’, ’0.1′ => ‘c’
e) A syntax error
My Ans: ( C )
Q5. Name three new extensions in PHP5
Answer (Choose 3)a) tidyb) soapc) javad) curl
e) mysqli
My Ans: (a, c, d)
Q6. What is the output of the following script
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
3/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php
$a = 1;$b = 2.5;$c = 0xFF;
$d = $b + $c;$e = $d + $b;$f = ($d + $e) % $a;
print ($f + $e)
?>
Answera) 643.75b) 432c) 643d) 257
e) 432.75
My Ans. (d)
Q7. One can determine if it is possible to send HTTP headers from within PHP script usingwhich of the following function?
Answera) apache_header_enabled()
b) is_header_enabled()c) is_header_sent()d) headers_sent()e) headers_enabled()
My Ans. (d)
Q8. Type-hinting and the instanceof keyword can be used to check what types of thingsabout variables?Answer (Choose 3)
a) If a particular child class extends from itb) If they are instance of a particular interface
c) If they are an abstract class
d) If they have a particular parent classe) If they are instance of a particular class
My Ans. (b, d, e)
Q9. When embedding PHP into XML documents what must you ensure is true in order for
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
4/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
things to function properly?
Answer
a) Disabling of the short_tags PHP.ini directiveb) Enabling the asp_tags PHP.ini directive
c) That you have XPath support enabled in PHP5d) That your XML documents are well formed
e) None of the above, PHP can be embedded in XML in all cases
My Ans. (d)
Q10. The following is a common XML structure used in service oriented architectures what
does it represent?
<?xml vesion=”1.0” ?><methodCall>
<methonName>myMethod</methodName> <params>
<param> <value><string>HI!</string></value>
</param>
</params></methodCall>
Answera) None of the above
b) A fragment of a complete SOAP request
c) XML-RPCd) REST
c) SOAP
My Ans. ( c )
Q11. The MVC pattern in web development involves which of the following components?
Answer (Choose 4)a) view
b) controller
c) validationd) model
e) front controller
My Ans. (a, b, d, e)
Q12. What is the output of the following?
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
5/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php
function a($number){
return (b($number) * $number);}
function b(&number)
{
++$number;}
echo a(5);
?>
Answera) 0
b) 36c) 6
d) 30e) 5
My Ans. (a)
Q13. PHP5 supports which of the following XML parsing method?
Answer (Choose 4)a) SAX
b) FastDOMc) DOM
d) Xpathe) XML to object mapping
My Ans. (a, c, d, e)
Q14. Given the following array
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
6/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php
$a = array(
1 => “red”, 'green',
'blue', 'purple' => array(
'house' => 'dog',
'food' => 'meal', 'here' => 'gone',
'hello' => array( 5 => 'goodbye',
8 => 'something', 'correct'
)
));
?>
Which out of the following print statements will output the string ‘correct’?
Answer
a) print $a['purple'][4][3]
b) print $a['purple']['hello'][9]c) print $a[2][4][3]
d) print $a[2][4][9]e) print $a[4]['hello'][9]
Q14. What variable referecne would go in the spots indicated by ????? in the code segmentbelow?
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
7/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php
$msg = “The quick brown foxed jumped over the lazy dog”;
$status = true;$retval = “”;for($i; isset(?????); $i++) {
if($state) { $retval .= strtolower(?????); }else{
$retval .= strtoupper(?????); } $state = !$state;
}
print $retval;
?>
Answer
a) $msg{$i}b) ord($msg);c) chr($msg);
d) substr($msg, $i, 2);
My Ans. (a)
Q16. Where should indirectly executed PHP script (i.e. include files) be stored in the filesystem?
Answer
a) Outside of the document rootb) In the document rootc) Anywhere you want
d) In the database
My Ans. (a). Users can easily access files such as config and log files if they are in documentfolder so it is safer to have them outside the document root folder.
Q17. What is the best approach to convert this string:$string =“a=10&b[]=20&c=30&$d=40+50Into this array?
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
8/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
Array(4) { [“a”] =>
string(2) “10” [“b”] => array( [0] => string(2) “20”
), [“c”] => string(2) “30”
[“d”] => string(5) “40 50”}
Answera) Writer a parser completely by hand, it’s the only way to make sure it’s 100% accurateb) Use the parse_str() function to translate it into an array()
c) Pass the variable to another PHP script via HTTP GET request and return the variable asserialized variabled) Just call unserialize() to translate it into an array().e) Write a string parser using strtok() and unserialize() to convert it to an array.
My Ans. ( c )
Q18. Consider the following PHP string representing SQL statement:
$query = “UPDATE users SET password = ‘$password’ WHERE username = ‘$username’”;
Which are the following values for username and password the behaviour of this query
when executed?
Answera) None of the above
b) $username = “foobar\’ WHERE username = ‘admin’”;c) $password = “foobar’ WHERE username = ‘admin’ –-:”;d) $username = “foobar’ WHERE username = ‘admin’”;
e) $username = “\”foobar\” WHERE username = \”admin\””;
My Ans. ( c )
Q19. What does the following function do, when passed two integer values $p and $q?
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
9/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php
function magic($p, $q){ return ($q == 0)
? $p : magic($q, $p % $q); }
?>
Answer
a) Loops infinityb) Switches the value $p and $qc) Determines if they are both even or odd
d) Determines the greatest common divisor between theme) Calculates the modulus between the two
My Ans. ( c )
Q20. Which function is best suited to removing mark up tags from a string?
Answer
a) strip_markup()b) strip_tags()c) str_replace()
d) preg_replace()e) preg_strip()
My Ans. (b)
Q21. When uploading a file using HTTP, which variable can be used to locate the file onPHP’s local filesystem?
Answera) None of the aboveb) $_FILES['fieldname']['tmp_name']
c) $_FILES['fieldname']d) $_FILES['fieldname'][0]['filename']e) $_FILES['fieldname']['filename']
My Ans. (b)
Q22. Given the two values below, which of the following possibilities will print 10 foos20bars?
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
10/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php
$var1 = “10 foos”;$var2 = “20 bars”;
print ?????;
?>
Answer (Choose 2)a) None of the aboveb) implode(“”, array($var1, $var2))
c) $var1 . $var2d) $var1 + $var2e) All of the above
My Ans. (b, c)
Q23. During normal filesystem access, the _______ function is used to determine if the
pointer has reached the end of the file
Answera) feof()
b) flock();c) fclose();d) fend();e) None of the above
My Ans. (a)
Q24. What is wrong with the following code snippet? Assume default configuration valueapply?
<?php
$fp = fsockopen('www.php.net', 80)fwrite($fp, “GET / HTTP/1.0\r\nHost: www.php.net\r\n”);$data = fread($fp, 8192);
?>
Answera) The request is blocking and may cause fread() to hangb) The HTTP request is malformedc) The script should be rewritten using fgets() instead of fread()
d) The request is non-blocking and fread() may miss the responsee) You cannot use fwrite() with fsockopen()
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
11/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
My Ans. (a)
Q25. When checking to see if two variable contains the same instance of an object which of
the following comparison should be used?
Answera) if($obj1->equals($obj2) && ($obj1 instanceof $obj2))
b) if($obj1->equals($obj2))c) if($obj1 === $obj2)d) if($obj1 instanceof $obj2)
e) if($obj1 == $obj2)
My Ans. ( c )
Q26. What is the output of the following code?
<?php
function functionSplit(){ $pre = 1;
?>
<?php echo $pre;
}
functionSplit();
?>
Answera) Error; function cannot be split over multiple segments
b) Nothingc) 1d) 2
My Ans. ( c )
Q27. Identify the best approach to compare to variable in binary-safe fashion
Answera) Both strcomp() and $a === $bb) $a == $b
c) $a === $bd) str_compare()e) strstr()
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
12/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
My Ans. (a)
Q28. What is the output of the following?
<?php
function 1dotEach($n){ if($n > 0) { 1dotEach(--$n);
echo “.”; }else { return $n; }}
1dotEach(4);?>
Answer
a) …0b) Parse Error; Syntax errorc) …..d) ….e) …
My Ans. (b)
Q29 Which of the following are not valid ways to embed a variable into a string?
Answer (Choose 2)a) $a = “Value: $value->getValue()”b) $a = “Value: {$value}”c) $a = ‘Value: $value’
d) $a = “Value: $value”e) $a = “Value: {$value['val']}”
My Ans. (a, c)
Q30. Consider the following code segment:
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
13/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?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>Virtual Library</title> </head> <body>
<p>Moved to <a href="http://example.org/">example.org</a>.</p> </body></html>XML;$xml = xml_parser_create(“UTF-8”);???????xml_parse($xml, $xmldata)
function xml_start_handler($xml, $tag, $attribute){ print “Tag: $tag<br/>\n”;}
function xml_end_handler($xml, $tag){
}?>
What should be placed in place of ??????? above to have the above script display the name ofeach tag within the XML document?
Answera) xml_set_callback(“xml_start_handler”)b) xml_set_element_handler($xml, “xml_start_handler”, “xml_end_handler”)c) xml_node_set_handler(“xml_start_handler”, “xml_end_handler”);
d) xml_node_set_handler(“xml_start_handler”);
My Ans. (b)
Q31. Consider the following series of classes and interfaces
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
14/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?phpinterface MyInterface { public function getTitleAndAuthor();}
class MyClass {
private $_author; private $_title;
public function getAuthor() { return $this->_author; }
public function getTitle() { return $this->_title; }}
class MyClass2 { private $_instance;
public function __construct(MyClass $a) { $this->_instance = $a; }
public function getTitleAndAuthor() { $retval = array(
'title' => $this->_instance->getTitle(), 'author' => $this->_instance->getAuthor() );
return $retval; }}
class MyClass3 { public function doSomething(MyInterface $instance) { $value = $instance->getTitleAndAuthor(); }}
?>
MyClass2 is an example of the _______ design pattern
My Ans. Registry Pattern
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
15/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
Q32. The _______ function is used to modify the amount of time PHP will wait for a stream
before timing out during reading or writing
My Ans. stream_set_timeout()
Q33. The _______ keyword used to block any overriding of a class/method by subclass
Answera) static
b) None of the abovec) protectedd) finale) private
My Ans. (d)
Q34. In a general sense, which is more important: performance or maintainability of anapplication
Answera) Performance first, maintainability secondb) Maintainability first, performance secondc) Maintainability
d) Performance
My Ans. (b)
Q35. When connecting to a database using PDO, what must be done to ensure that databasecredentials are not compromised if the connection where to fail.
Answer
a) Wrap the PDO DSN in a try/catch block to catch any connection exceptionb) Use constants in the PDO DSNc) Place login credentials in the php.ini filed) Disable E_STRICT and E_NOTICE error reporting levels
My Ans. (a)
Q36. The _______ construct is particularly useful to assign your own variable names tovalues with in an array.
Answera) array_get_variablesb) currentc) each
d) import_variablese) list
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
16/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
My Ans. (e)
Q37. What is the output of the following script
<?phpclass ClassOne { protected $a = 10;
public function changeValue($b) { $this->a = $b; }}
class ClassTwo { protected $b = 10;
public function changeValue($b) { $this->b = 10; parent::changeValue($this->a + $this->b); }
public function displayValues() {
print “a: {$this->a} b: {$this->b}\n”; }}
$obj = new ClassTwo();
$obj->changeValue(20);
$obj->changeValue(10);
$obj->displayValues();?>
Answera) a: 30 b: 30b) a: 30 b: 20c) a: 30 b: 10d) a: 20 b: 20
e) a: 10 b:10
My Ans. ( c )
Q38. Consider the following PHP script fragment:
01/06/2012 Zend PHP 5 Certification Practice Test 1 « Life of Miz
17/17getmizanur.wordpress.com/2010/07/13/zend-php-5-certification-practice-test-1/
<?php$title = $dom->createElement('title');
$node = ???????
$title->appendChild($node);$head->appendChild($title);
?>
What should ??????? be replaced with to add a