Zend Certification Practice Exam

  • Post author:
  • Post category:PHP
  • Post comments:4 Comments

In preparation for the Zend Certification Exam (ZCE), Zend provides a great (sarcasm) online practice test that consists of 8 questions. That is right, 8 questions. A certification exam that consists of 70 questions and Zend offers 8 questions. And the other thing with the practice test, is that if you get 5 out of 8 correct, then you are “ready” to take the exam. Which I would not suggest, unless of course you have at least 1 year of real PHP experience coding, testing, even hacking. Plus, there is a good amount of DB stuff on the test, as well as security, streams, XML/Web Services and other stuff. I also suggest you pay (that is right, pay) for a set of practice exams. But I digress. Back to the Zend practice test. They give you 8 questions, then just tell you how many you got right/wrong. There is no feedback (like a real exam) on the practice test, which I think there ought to be. So I decided I would not only give you the answer, but why it is the answer. Following is the exam questions and the answers and why they are the answers.

1. How can precisely one byte be read from a file, pointed by $fp?
A) 		fseek($fp, 1)
B) 		fgets($fp, 1)
C) 		fgetss($fp, 1)
D) 		fgetc($fp)
E) 		All of the above 
  • A. fseek($fp,1) will set the position in the file based on the offset, which in this case is “1”. This will not read one byte, but rather set the position at a byte specified by the offset, so this answer is not correct.
  • B. fgets($fp,1) will read one line of the file. So this will obvious get the one byte, but it will get much more than that, so this answer is not correct.
  • C. fgetss($fp,1) will do the same as above, read the entire line, but it also tries to strip any HTML and PHP tags it finds, so this can not be the correct answer.
  • D. fgetc($fp,1) is the correct answer. This function, think of it as fgetcharacter, (fgetc), which will return 1 byte from the file pointer. There are some instances where this may not be the best (like special characters in UTF-8, but the exam is looking for this answer.
  • E. is not correct because the other options are not correct. If you see questions like this, and eliminate even 1 possibility, then this is not correct.
2. What object method specifies post-deserialization behavior for an object?
A) 		__sleep()
B) 		__wakeup()
C) 		__set_state()
D) 		__get()
E) 		__autoload() 
  • A. __sleep is the magic function that performs clean up of objects and serializes the variables and returns an array with the names of the variables. This would be an incorrect answer.
  • B. __wakeup is another magic function that will reconstruct the resources that may have been lost, ie reconnect the DB connections. This would be the correct answer as it is what unserialize() checks.
  • C. __set_state only is used when classes are exported by var_export(). This is not a correct answer.
  • D. __get is used with overloading, used to read data from inaccessible members, again, not a correct answer.
  • E. __autoload would be a customized magic function, and not a correct answer.
3. Where does the session extension store the session data by default?
A) 		SQLite Database
B) 		MySQL Database
C) 		Shared Memory
D) 		File System
E) 		Session Server
  • A. SQLite – This is not the default storage for sessions, and usually not the best place to put sessions anyway. This is not a correct answer.
  • B. MySQL – Since the question is worded with the key word “default”, this can not be correct. A database approach to session storage is good for large traffic sites, but this is not the correct answer.
  • C. Shared Memory -This is one of those answers thrown in to make it look viable, but obviously it would not share memory with sessions.
  • D. File System PHP’s default session storage is in the temp (tmp) directory of the system. This is the answer they are looking for.
  • E. Session Server – again, like B and C, it is not a correct answer.
4. Which of the following data types cannot be directly manipulated by the client?
A) 		Cookie Data
B) 		Session Data
C) 		Remote IP Address
D) 		User Agent 
  • A. Cookie data is stored on the client and is easily manipulated, so this is not correct.
  • B. Session Data Session data is stored on the server, and therefore would be the correct answer as the client has no direct access to it.
  • C. Remote IP Address is incorrect as there are a ton of ways to now spoof IPs, including using certain websites like Anonmizer to hide your IP address.
  • D. User Agent can be forged as easily as cookie and IP addresses. This is not a correct answer.
5. What is the difference between isset() and other is_*() functions (is_alpha(), is_number(), etc.)?
A) 		isset() is a function call and is_*() are not function calls
B) 		is_*() are language constructs and isset() is not a language construct
C) 		isset() is a language construct and is_*() are not language constructs
D) 		is_*() return a value whereas isset() does not 
  • A. isset() is a function, but is_* are also functions, so this is not correct.
  • B. is_* are language constructs is a false statement, thus making this answer incorrect.
  • C. isset() is a language construct and therefore is the correct answer. It is built into the language and can not be used with variable functions like the other options.
  • D. is_*() returns a value, but isset() also returns TRUE or FALSE, so this can not be correct.
6. What will be the value of $b after running the following code?
$a = array('c', 'b', 'a');
$b = (array) $a;
A) 		TRUE
B) 		array('c', 'b', 'a')
C) 		array(array('c', 'b', 'a'))
D) 		None of the above 
  • A. TRUE is incorrect as an answer here because what is being done in the example is type casting. This is not a correct response to the question the way it is worded.
  • B. array(‘c’,’b’,’a’) is correct because the variable b is being set to $a and cast as an array.
  • C. array(array(a,b,c) is not correct as there is no multidimensional array happening here. So this is incorrect.
  • D. None of the above would not be correct because B is the right answer.
7. Which of the following function signatures is correct if you want to have classes automatically loaded?
A) 		function autoload($class_name)
B) 		function __autoload($class_name, $file)
C) 		function __autoload($class_name)
D) 		function _autoload($class_name)
E) 		function autoload($class_name, $file) 
  • A. autoload($class_name) would be incorrect because what PHP would be looking for is a “magic” function to automatically load a class.
  • B. __autoload($class_name, $file) would be incorrect as it is looking for a class name, not additional files and parameters.
  • C. __autoload($class_name) is correct because it is the magic function that PHP is looking for, with the class name as the paramater.
  • D. _autoload is incorrect as magic functions will always have 2 underscores, ie __
  • E. autoload($class_name, $file) is incorrect much the same reason as answer A.
8. What is the best way to run PHP 4 and PHP 5 side-by-side on the same Apache server?
A) 		Run one as an Apache module, the other as a CGI binary.
B) 		Run both as a CGI binary.
C) 		Just use .php4 for PHP 4, and .php for PHP 5.
D) 		Use .php for both but use different document roots. 

Here is where the great debate can begin. However, in order to understand this answer, you need to understand the question. This question (and exam) are going to be testing your knowledge of PHP and Apache. Could each answer have its own strengths? Yes. What is the best way to run php4 and php5 side by side? My answer would be DON’T. Upgrade all code to php5, php4 is no longer supported and now “deceased”. However in some cases you would not be able to. So looking at the question again, you can break it down thusly:
– The question is about PHP running on Apache
– The question is looking for an answer on the SAME Apache server
– The only viable correct answer in this case is A

  • A is the correct answer. This is because the question says you are running PHP on Apache. The other way to run a different version is CGI binary
  • B. Running both as CGI binary still does not solve the problem, and ignores the point of the question.
  • C. Using a different extension does not really solve problems for application in php4 that still have extensions of *.php. That would cause overhead and man hours to change extensions
  • D. While this really would not solve the problem of php4/php5 side by side, it also ignores the real root of the question

Now, if you got all 8 questions correct, congratulations! According to Zend, you are ready to take the exam. My advice, study first. Look through the PHP manual, take the real practice exams, get ready for questions like this:

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:
$retval = flock($fr, LOCK_EX);
a. Use flock_lazy() instead of flock()
b. Use LOCK_EX|LOCK_NB instead of LOCK_EX
c. Use LOCK_UN instead of LOCK_EX
d. Check the value of $retval to see if the lock was obtained
e. Check to see if $retval == LOCK_WAIT

This Post Has 4 Comments

  1. Vicky

    Thank you

  2. Thor

    b. Use LOCK_EX|LOCK_NB instead of LOCK_EX

  3. James

    Practice exams are an excellent way to study for exams!

    Wonderful content! Keep up the good work!

    Thanks,

    James

  4. Craig R Morton

    Many thanks for posting up these questions. I have found it quite hard to find practice questions online (other than the practice exams I paid for) and even harder finding explanations of answers.

    Thank you,
    Picco

Leave a Reply