Zend Certification Self Test
11 Apr 2005In Preparing for the Zend Certification, I provided the answers (with explanations) to the Zend PHP Certification Self Test. Zend has since updated the self test, so I'm again providing the answers to it. Of course, I recommend that you take it before you read this - this is for those who don't understand a particular answer or can't figure out which one(s) they missed.
Question 1
A. 3
B. False
C. Null
D. 1
The answer is D (1), because only a single argument is given to count(). Incarnations of this question typically confuse people due to the fact that count() is almost always used to count elements in an array, so they're not familiar with using it in any other context. Aside from that, it's pretty straightforward.
Question 2
42 with two decimal places?
A. printf("%.2d\n", 42);
B. printf("%1.2f\n", 42);
The answer is B. This question only requires that you remember the basic format strings for functions like printf() and sprintf().
Question 3
$text = 'Content-Type: text/xml';
Which of the following prints 'text/xml'?
A. print substr($text, strchr($text, ':'));
B. print substr($text, strchr($text, ':') + 1);
C. print substr($text, strpos($text, ':') + 1);
D. print substr($text, strpos($text, ':') + 2);
The answer is D. The string position of : (the colon) is two less than the string position of the t, so strpos($text, ':') + 2 provides the string position of the t. The substr() syntax therefore says that we want the substring of $text that begins with the t and continues to the end of the string.
Question 4
<?php
$a = 123 == 0123;
?>
A. True
The answer is B (False). This question is challenging, because you must know that PHP treats 0123 as the octal representation of 83 due to the leading zero (64 + 16 + 3 = 83).
Question 5
<?php
function timesTwo($int)
{
$int = $int * 2;
}
$int = 2;
$result = timesTwo($int);
The answer is null, because timesTwo() doesn't return anything.
Question 6
<?php
class Foo
{
?>
<?php
function bar()
{
print "bar";
}
}
?>
A. will work, class definitions can be split up into
multiple PHP blocks.
B. will not work, class definitions must be in a single PHP
block.
C. will not work, class definitions must be in a single file
but can be in multiple PHP blocks.
D. will work, class definitions can be split up into
The answer is B, because class definitions must be in a single PHP block.
Question 7
different variables from HTML forms and cookies.
A. show_errors, enable
B. show_errors, show
C. register_globals, enhance
The answer is D. While the first two answers make no sense, both C and D seem viable, and the difference between the two seems entirely subjective. If you consider register_globals to have a negative connotation, you're more likely to think of its behavior as injecting rather than enhancing. However, I'm not sure that a distaste of register_globals is a necessary characteristic of an expert PHP developer.
Question 8
<?php
echo count(strlen("http://php.net"));
The answer is 1. This is almost the same question as the first one, so the only challenge is understanding what count() does when given something other than an array.