Debugging Code and Managing Performance

NO MATTER HOW EXPERIENCED a developer you are, or how hard you’ll try, your applications will have bugs. They’re an inevitable part of life, like death and taxes (although usually—but not always—less dangerous an expensive than the latter).

Being able to identify bugs is the first step towards resolving them. In fact, many developers spend countless hours staring blankly at a page of code only because their applications don’t have good error-monitoring capabilities in the first place. Ignoring this aspect of programming is a bit like hoping that bugs will never happen: hopeless!

The questions of the Zend Exam that focus around this area test your basic knowledge of topics related to debugging and optimizing code, as well as on the facilities that PHP provides for this specific purpose.

Questions

1. Which of the ternary operations below is the equivalent of this script? <?php 
 
if ($a 10) { 
  if (
$b 11) { 
    if (
$c == 10 && $d != $c) { 
   
$x 0
  } else { 
   
$x 1
  } 
 } 

 
?>

A.
B.
C.
D.
E.

2. Which of the following measures can help improving the performance of a script that is slow due to the fact that it needs to pull data from a remote source that is not under your control? (Choose 2)

A.
B.
C.
D.
E.

3. Which of the following are good steps to undertake when setting up a production webserver? (Choose 2)

A.
B.
C.
D.
E.

4. The __________ operator makes comparisons stricter by checking the types of its operands against each other.

Your answer:

5. What does an opcode cache do?

A.
B.
C.
D.
E.

6. Which of the following could result in resource starvation? (Choose 2)

A.
B.
C.
D.
E.

7. What’s missing from the following script? (Choose 2) <?php 
 
$rs 
database_query ("select * from mytable where id = " 
                      
$my_id); 
 
while (
$a database_get_data ($rs)) { 
 
var_dump ($a); 

 
?>

A.
B.
C.
D.
E.

8. Which of the following error types cannot be caught by setting up a custom error handler? (Select two)

A.
B.
C.
D.
E.

9. When comparing a constant value against a variable, what is a good way to ensure that you will not mistakenly perform an assignment instead?

A.
B.
C.
D.
E.

10. What is the easiest way to send an error message to a systems administrator via e-mail?

A.
B.
C.
D.
E.

11. Can you turn off all error reporting from within a script with a single PHP function call?

A.
B.

12. What is the role of a profiler?

A.
B.
C.
D.
E.

13. A ____________ can help identify and solve bugs.

Your answer:

14. What is the difference between trigger_error() and user_error()?

A.
B.
C.
D.
E.

15. The _______________ function can be used to retrieve the sequence of code function calls that led to the execution of an arbitrary line of code in a script. This function is often used for debugging purposes to determine how errors occur.

A.
B.
C.
D.
E.