p. Now that you’ve used PHP with MySQL and SQLite, you probably think you know everything you need to get started with PHP programming. In fact, you might even be thinking of cutting down your visits to Zend.com altogether, giving up this series for something flashier and cooler…
p. PHP 101 (part 10): A Session In The Cookie JarUh-uh. Big mistake.
p. Unless you’ve been hiding in a cave for the last few years, you’ve heard about XML – it’s the toolkit that more and more Web publishers are switching to for content markup. You may even have seen an XML document in action, complete with user-defined tags and markup, and you might have wondered how on earth one converts that tangled mess of code into human-readable content.
p. The answer is, not easily.
p. Even the best developers make mistakes sometimes. That’s why most programming languages – including PHP – come with built-in capabilities to catch errors and take remedial action. This action can be as simple as displaying an error message, or as complex as sending the site administrator an email with a complete stack trace.
p. To make it easier to do this, PHP comes with a full-featured error handling API that can be used to trap and resolve errors. In addition to deciding which types of errors a user sees, you can also replace the built-in error handling mechanism with your own custom (and usually more creative) functions. If you’re using PHP 5, you get a bonus: a spanking-new exception model, which lets you wrap your code in Java-like try-catch() blocks for more efficient error handling.
p. In this edition of PHP 101, I’m going to discuss all these things, giving you a crash course in how to add error-handling to your PHP application. Keep reading – this is pretty cool stuff!
p. Maybe you’ve heard the term GIGO before.
p. If you haven’t, it stands for Garbage In, Garbage Out, and it’s a basic fact of computer programming: if you feed your program bad input, you’re almost certainly going to get bad output. And no matter which way you cut it, bad output is not a Good Thing for a programmer who wants to get noticed.
p. After the workout I gave you last time, you’re probably either chomping at the bit to build another PHP application or you’ve decided to give up PHP programming and try growing cucumbers instead. If it’s the latter, you should stop reading right now, because I can guarantee you that this concluding installment of PHP 101 has absolutely nothing to teach you about vegetable farming.