About the Author

Chris Shiflett

Hi, I’m Chris: entrepreneur, community leader, husband, and father. I live and work in Boulder, CO.

All posts for Apr 2005

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


$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?


= 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? 


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 __________. 


class Foo



function 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
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: 


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.

PHP Quebec Recap

As usual, I failed to really keep up with blogging while at my last conference. After returning, I realized that it would be very difficult to adequately describe the experience in words. PHP Quebec turned out to be one of the best conferences I've attended.

Toby has quite a few pictures of the experience. There are also several posts about the conference:

If you know of any others, please post them in the comments. Thanks to Damien and the rest of the organizers for such a great experience.