Zend Certification Self Test
In 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
What does <? echo count ("123") ?> print out?
A. 3
B. False
C. Null
D. 1
E. 0
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
Which of the following snippets prints a representation of
42 with two decimal places?
A. printf("%.2d\n", 42);
B. printf("%1.2f\n", 42);
C. printf("%1.2u\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
Given
$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);
E. print substr($text, 0, strchr($text, ':'));
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
What is the value of $a?
<?php
$a = 123 == 0123;
?>
A. True
B. False
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
What is the value of $result in the following PHP code?
<?php
function timesTwo($int)
{
$int = $int * 2;
}
$int = 2;
$result = timesTwo($int);
?>
The answer is null, because timesTwo() doesn't return anything.
Question 6
The code below __________ because __________.
<?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
multiple files and multiple PHP blocks.
The answer is B, because class definitions must be in a single PHP block.
Question 7
When turned on, __________ will __________ your script with
different variables from HTML forms and cookies.
A. show_errors, enable
B. show_errors, show
C. register_globals, enhance
D. register_globals, inject
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
What will be the output of the following PHP code:
<?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.





173 Comments
1.
JD said:
2.
david said:
3.
Chris Shiflett said:
4.
Al said:
5.
Alec said:
6.
Matt H said:
7.
Per Persson said:
8.
Kristian said:
9.
Shaun said:
10.
Jim Plush said:
11.
Alec said:
12.
Al said:
13.
Alec said:
14.
tepp said:
15.
Ryan Wray said:
16.
Certify This said:
17.
Arnór Heiar said:
18.
Arnor Heidar said:
19.
Arnor Heidar said:
20.
Compuchuck said:
21.
Morgan Craft said:
22.
Steven Van Poeck said:
23.
Stuart said:
24.
ni2k said:
25.
Hamad said:
26.
Haseeb said:
27.
Paulo said:
28.
Artyom said:
29.
Jaygiri said:
30.
Conrad said:
31.
Dhiraj Patra said:
32.
Thomas Gruner said:
33.
BrijKumar said:
34.
anon said:
35.
ccp said:
36.
Shurik said:
37.
incous said:
38.
Karolis Tamutis said:
39.
Phu said:
40.
Klaus said:
41.
XAnkth said:
42.
Yurgh said:
43.
red said:
44.
Jon said:
45.
Stefan said:
46.
ekt said:
47.
Chris Shiflett said:
48.
Harshit Sekhon said:
49.
Alex said:
50.
Naif Meelbi said:
51.
DiZpel said:
52.
Praveen Kumar M [INDIA] said:
53.
moh bahdoon said:
54.
Nermin Hanjalic said:
55.
dEEPS said:
56.
CK said:
57.
PATTERSON said:
58.
FM said:
59.
premlal said:
60.
karlosprog said:
61.
Junior said:
62.
cdanea said:
63.
cdanea said:
64.
said:
65.
mano said:
66.
said:
67.
simon said:
68.
Arnold Smyth said:
69.
chris said:
70.
Aaron said:
71.
KVJ said:
72.
Albert said:
73.
Streaky said:
74.
Seba said:
75.
JamesBenson said:
76.
JD said:
77.
bob kennedy said:
78.
Sean Benoit said:
79.
Siva Prem said:
80.
Brandon said:
81.
Josh Fox said:
82.
Pepito Grillo said:
83.
Scoobs said:
84.
Darkwing said:
85.
kk said:
86.
cberry said:
87.
Bryan King said:
88.
Bryan King said:
89.
Dharmendra Ajwani said:
90.
John-Henrique F. Silva said:
91.
Ralph Almeida said:
92.
Michael Drinnan said:
93.
Noel said:
94.
Chris Shiflett said:
95.
Fat Albert said:
96.
Rui Gomes said:
97.
Christopher kalu said:
98.
WP said:
99.
Prabir Dutta said:
100.
Bharathiraja said:
101.
Madhur Kumaria said:
102.
Vitas said:
103.
Sudhir Chauhan said:
104.
PUNEET said:
105.
Alex said:
106.
ashish said:
107.
guest said:
108.
K Therrault said:
109.
Doesnt Know PhP at all said:
110.
Rocky said:
111.
Dhanasekar.G said:
112.
Mike Walters said:
113.
hafizan said:
114.
SK said:
115.
SK Again! said:
116.
SK said:
117.
Michael said:
118.
Jose said:
119.
Dave said:
120.
Dave said:
121.
Nate Klaiber said:
122.
Anh N. said:
123.
Vlasis said:
124.
Jenny said:
125.
Amjad A. said:
126.
Nate Klaiber said:
127.
Abhijit said:
128.
Doug said:
129.
FokeyJoe said:
130.
Robin Vickery said:
131.
Robin Vickery said:
132.
Randell Benavidez said:
133.
Gonzola said:
134.
Wayne said:
135.
Sharon Levy said:
136.
Sharon Levy said:
137.
Sharon Levy said:
138.
Sharon Levy said:
139.
Sharon Levy said:
140.
Sharon Levy said:
141.
Sharon Levy said:
142.
Sharon Levy said:
143.
Mike Willbanks said:
144.
Phillip said:
145.
Phillip said:
146.
Nate Klaiber said:
147.
Bryan said:
148.
Vivian said:
149.
Matthias Esken said:
150.
bansidhar said:
151.
t black said:
152.
chirayu bhatt said:
153.
heynow said:
154.
Some Guy said:
155.
Grim said:
156.
Peter Brodersen said:
157.
Tom said:
158.
Ronald Roush said:
159.
biju said:
160.
robert robles said:
161.
Princevel said:
162.
Muhammad Fareed said:
163.
Brad said:
164.
Royce said:
165.
Julian Egelstaff said:
166.
WeeWee said:
167.
Dan said:
168.
Andy Baptiste said:
169.
anon. said:
170.
tan said:
171.
tan said:
172.
Ralph said:
173.
Abhijit said: