Hudzilla.org - the homepage of Paul Hudson
Contents > Writing PHP > Debugging Wish List | Report Bug | About Me ]

19.8.1     What is a bug?

This is NOT the latest copy of this book; click here for the latest version.

While attending O'Reilly's Open Source Convention 2004, I met a chap called Donald Bales. He's a published author (if you're into Oracle and JDBC, there are no better books than his) who also works full-time as a enterprise application development consultant. What he said to me was that he doesn't call a bug a "bug"; it's a "defect". The very best consultants are invariably a good mix between a talented programmer and a skilled dipomat, so I can see where "defect" applies. For the rest of us, though, I think it's important to use the word "bug" because most programmers immediately understand what it means, whereas "defect", while better for management types, is a little hazy.

So, what is a bug? There are several types:

  • A syntax error is where you've managed to physically type your script incorrectly: you're missing a semi-colon, a quote, or you've got too many braces.

  • A semantic error is where your code is correct, but probably not what you intended: adding 5 to "foo" is acceptable PHP, but usually wrong.

  • A logic error is where your code takes the wrong path because you got confused, for example using && rather than || or not using a ! to negate an if statement.

  • A runtime error is where PHP has loaded your code, parsed it, and everything is fine, but it cannot be executed. Perhaps you've called a function from an extension that isn't loaded, perhaps you've supplied the wrong password for an FTP server, etc.

I know this is a huge, huge generalisation, but I venture to say that you'll find most of your errors are of the first type: syntax errors. Fortunately they are the easiest to find and fix, and aren't fatal: PHP always catches syntax errors before it attempts to execute the script, so you know that as soon as no more syntax errors are caught there won't ever be any as long as you don't change it.

On the flip side, real logic errors are a little harder to spot, and may lurk in your code for weeks (years?) before they come to light. These are a little rarer, though, and it's only practice that can help you solve them.

Over the coming chapters we're going to look at various ways to solve bugs, and, although it's not a requirement to remember what the different types of bugs are, it might help you now and then.





<< 19.8 Debugging   19.8.2 The most basic debugging technique: debug_zval_dump() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is three plus nine?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow