scriptNode

Web development with a focus on JavaScript RSS

Interview Questions Part 1: PHP

Intermediate Matt Hackett Published July 12th, 2008 by Matt Hackett

I interview a lot of people. Sometimes for a specific task, and sometimes just because we need more engineering power. In the latter case, it's usually enough to be a good, experienced engineer in almost any language. But usually we're hiring for a job heavy on one language or another, and it's my job to find out if the candidate is fluent.

This is the first part of many articles I'm going to write about common interview questions in the vague and mysterious world of web development. There are of course an almost infinite amount of questions one could be asked during an interview, but my questions are typically going to be more about syntax and semantics than the probably more revealing questions on algorithms and problem-solving.

Without further ado, here are some common questions engineers get asked to see if they understand the basic syntax of PHP.

Q: What are the differences between single and double quotes?

A: The primary difference is that a string enclosed with double quotes is parsed. A string enclosed in single quotes is just a string literal.

Q: What are the differences between include() and require()?

A: The most prominent difference is that require() will throw an error if it fails to include the given file, and include() will not.

Q: What does the === operator do?

A: Triple equals checks for both value and type:

I like to ask if the engineer can think of an example (like the one above). It's almost guaranteed that a programmer that has been developing in PHP for an extended period needed === before.

Q: What does $$ signify?

A: Double dollar sign signifies a variable variable:

Q: What are the various ways to append to an index array?

A: [see code]

I like this question because it's easy on the surface, and engineers will almost always get the first two. When I say there's one more way, an engineer's response is usually pretty revealing. Getting an answer like, "No there's not," shows (unearned) arrogance. Candidates that figure it out on their own show thinking on their feet.

Q: How do you debug in PHP?

I think it's probably most common for developers to use the quick-and-dirty echo statement. A better practice is to use error_log or an external debugging library, because they won't muck up the page and potentially cause other bugs.

Q: Create a class and extend it.

Not really a question, but still important. I also ask about constructors and deconstructors, and make sure the candidate knows how to call the extended class's constructor:

I also like to ask if public is required (it's not because it's the default state), and make sure that the engineer knows about protected as well. I like to have conversations about object-oriented programming rather than just asking syntax questions, because I've found it's easier.

That's it, really. These questions are just to see if an engineer is familiar with the surface of the language. It could be argued that PHP is simple and quick to learn, and that these questions would shine a positive light on someone who spent a few hours reading about PHP, and a negative light on experienced engineers who are fantastic but not very familiar with PHP. It's a valid argument, but again, this is just to test PHP knowledge.

If you know any questions similar to these, I'd love to hear about them in the comments.

Read other articles tagged: , ,

Thoughts?

(required)

© 2009 scriptNode