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 Oct 2004

Handling 404 Errors with PHP

The PHP site does some nice trickery with 404 errors (plus 401 and 403). This is what accomodates short URLs like http://www.php.net/security. Want to do something similar on your own site? I see people asking how to do this all the time, even though the entire site is open source. Just have a look at the error.php script and write something similar for your own site. Use Apache's ErrorDocument directive to have your own error.php script handle any error code you want:

ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php

If you have a more flexible error script that people can implement with less hacking, feel free to let me know (or just leave a comment).

Guru Speak

The latest edition of PHP Magazine includes a new column that I will be writing called Guru Speak. I have been given a lot of flexibility in terms of the topics that I choose to write about, but one recurring topic will be providing thorough answers to common questions. The topic for this first edition is How to Avoid "Page Has Expired" Warnings, and PHP Magazine has graciously published this article on their Web site. Read it, and feel free to let me know what you think. You can also suggest questions of your own, although the PHP-General mailing list will remain my largest source of inspiration for the questions.

Thanks to PHP Magazine and PHPDeveloper.org for the extra press.

Foxylicious - Firefox Finally Groks del.icio.us

Someone finally wrote a good Firefox extension for del.icio.us. It's called Foxylicious. What makes it good? It does exactly what I described in my previous comments about del.icio.us:

Now, if only there were browser plugins for Firefox and Safari that integrated del.icio.us into the standard bookmark mechanism (with some intelligent caching to minimize traffic).

This extension adds my del.icio.us bookmarks to my standard bookmarks menu in Firefox, organizes them by tags (alphabetizing these would be a nice improvement), and lets me choose when to update them (so that it's not an abusive client). Other extensions just never seemed to grok it, as I mentioned before:

I've looked at this Firefox extension, but I fail to see what it offers that I don't already have. Giving me the ability to post is great and all, but this bookmarklet already does that (I use the popup version).

Well done, Dietrich. Foxylicious is exactly what I needed.

Preparing for the Zend Certification

In the past week or so, there has been a lot of discussion about preparing for the Zend Certification exam. A common concern people have is whether they can expect to pass it, and this is understandable. Even when you've been developing in PHP for a few years, you may only be familiar with a small subset of PHP's features. Another valid concern is whether the exam asks questions that are tricky or obscure. Some people are worried about missing questions on topics that they understand very well.

For anyone concerned about the presence of obscure questions or the quality of the exam in general, I can tell you that Zend did not create this exam in isolation. They chose an advisory board to establish the target audience, determine the criteria, and write the questions. We all worked together, so poor questions were revised or thrown out before making it to the beta exam. A psychometrician performed a quantitative analysis of the results of the beta exam, and more questions were eliminated as a result of this. Only questions of the highest quality remain, and small improvements not affecting the difficulty of the exam are currently being made. More information about the creation of the exam is available as part of Daniel Kushner's presentation, Attacking the PHP Job Market.

For those wanting to get a small taste of the exam, Zend is offering a self test with 5 practice questions. If you haven't already taken it, go ahead and try it - it only takes a couple of minutes. When you're finished, read below for my comments.

Question 1

What is the value of $a? 

= 123 == 0123;
?> A. True B. False

I think this question is a bit tricky, because it requires you to realize that 0123 is interpreted by PHP to be the octal representation of 83 due to the leading zero (64 + 16 + 3 = 83). Other than this, the question is good in that it requires you to understand how assignments and comparisons work. The answer is B (False).

Question 2

What is the value of $result in the following PHP code? 

function timesTwo($int) {
$int = $int * 2;

$int = 2;
$result = timesTwo($int);

I think this is a very good question. It requires that you understand how functions and return values work. I think any PHP developer wanting to be certified should understand functions very well - return values, passing by reference, passing by value, function local scope, the global keyword, and how all of these things work. In this question, because timesTwo doesn't return anything, the answer is null.

Question 3

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

This questions requires that you notice the presence of two PHP blocks and recognize that class definitions must be in a single PHP block. My only complaint with this question is that it's difficult for a developer to deduce the answer - it's just something you have to know. On the other hand, the presence of HTML in the middle of a class definition would be an obvious problem, because it makes no sense in this context. I would expect a developer to be able to answer this question correctly, but it might take a few minutes to think about it. The answer is B (will not work, class definitions must be in a single PHP block).

Question 4

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

This is not a good question. 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 don't think a distaste of register_globals is a necessary characteristic of an expert PHP developer. The answer is D (register_globals, inject).

Question 5

What will be the output of the following PHP code? 

echo count(strlen('http://php.net'));

I like this question. It assumes that you are familiar with the functions count and strlen, but I think this is a safe assumption, and I think it is easy to deduce what these functions do anyway. This question is likely to be missed by the same people who might execute a query that begins with select count(*) and then wonder why mysql_num_rows always returns 1. The answer to this question is 1, because strlen returns a single value - the length of the string.

Hopefully my analysis of Zend's self test gives you a small taste of the types of questions you're likely to encounter on the exam. While I'm just one member of the advisory board, the others tend to share my dislike of obscure questions, and I think the questions that remain are straightforward and well-written.

Zend also has a FAQ available that includes the exam objectives. Use these to direct your studies.

If you're planning on taking the exam, you can save yourself $200 by being the first to solve this puzzle. Zend is offering a free pass to the winner.