Function Caching in PHP
Using static variable as a function's cache
Read more →
Using static variable as a function's cache
Which is faster? Does it matter?
How to get the calling function in PHP

PHP has great debugging functions. By wrapping one we can find out who the caller of a function is. This blog entry gives a code snippet that returns the name of the function who called the current function by looking at the debug of the stack.
Read more →Dyslexic Developers Cry Shenanigans
PHP IBM DB2 iSeries Database Connection
Implementing ArrayAccess

In this installment, we will be exploring one of SPL's frequently used interfaces, the ArrayAccess interface. By implementing this interface, a class can allow its objects to be accessed as if they were arrays. This approach is particularly useful for setting up accessor methods for a class (getters and setters), though it can be used for almost any purpose. Let's dig a little deeper...
Read more →The SP-whatnow?

With the advent of PHP 5.0 came a new collection of built in classes and interfaces known as the Standard PHP Library (SPL). The goal of this library is to "solve standard problems and implements some efficient data access interfaces and classes." What gives this library an edge over other third-party offerings is its tight integration into the core of the PHP language and data structures. In this series of blog posts, I will attempt to showcase some of the more useful components of this library.
Read more →It's not as bad as you'd think
Sometimes, you just need a way to GOTO. Here is a little trick that will duck out of a section of code using break
Read more →PHP now comes with a carry-on!

Today I discovered a very powerful addition to the PHP world. Phar is an archive extension for PHP that allows an entire PHP application to be packaged into a single file. It's basically PHP's answer to Java's .jar archive format. Don't get excited yet, it gets better...
Read more →Not just an endeavor in aesthetics!

Having recently discovered the plethora of coding fonts available online, it occurred to me that quite a bit of thought has been put into something I have always seen as rather trivial. The more I read about it, the more I have come to realize that using a font specifically designed for software development can be extremely beneficial.
Read more →Say what?!

The Mini in a Nutshell

An API reference does a method's body good...

. . . but in a good way!

I stumbled upon a fantastic PHP class today and felt compelled to comment on it. Originally written by Tyler Hall, this class allows you to send notifications to any system running Growl from a PHP script. For those of you that don't know, Growl is an application written for Mac OS X that is intended to act as a universal notification tool (much like the taskbar notification bubbles we've all come to know and love in Windows XP/Vista).
PHP's next major release is just that, major!

The TO Pattern

Use open-source with more confidence

Try adding a parameter to the mail() function
Email debugging is often frustrating and time consuming. There could be numerous reasons why the email you attempted to send out through your code fails: routing issues, firewalls, company servers blacklisting or blocking incoming emails, spam filters, bad DNS records, and email header requirements. The last one can definetely lead to infinite frustration, as I have experienced in the past, and was recently the cause of why AOL was denying emails generated by the php mail() function.
Read more →The DAO and VO Patterns

In this installment, we will be looking at two patterns that have been 'borrrowed' from Java. If you've had any development experience with J2EE, you are probably well aware of how handy Data Access Objects and Value Objects can be. If you haven't, don't fret! This article was written especially for you!
If you've never heard these terms before, you may be wondering why I have chosen to group them together within one article. The simple explanation is ... well you'll see. For now just accept that they go hand-in-hand, much like salt and pepper or peanut butter and jelly or
Excited? Let's dig deeper...
Read more →The Registry Pattern

This is the first in a planned series of articles discussing the application of various PHP patterns. If you're still getting your feet wet developing in PHP (or programming languages in general), you may be wondering what a "pattern" is in the first place. The best place to find a quick explanation is over in Wikipedia's article (which does a much better job than I could hope to do within the scope of this article).
Now, let's move on to the fun part . . .
There are a number of reasons why you may want to capture a web user's IP address. You may want to only allow certain IP addresses to view your website, to allow only one vote per IP address, track unique clicks on links and buttons, a location of web users on Google Maps using MASHUP, and whatever else you can think of.
Below are a couple of examples to get the client's IP address in PHP and ASP.net, along with a couple of things to watch for.
Read more →Passing Arguments To Command Line
When attempting to use the SMTP library from PEAR for a project, I was having problems with including the file. I kept getting a file stream error for this code:
require 'Net/SMTP.php';I figured the problem had to be related to the include_path setting in the configuration file.
PHP Asynchronous Programming
Over the past few weeks, Reena has been building a new website off and on for a local Jesuit parish. Everything was going along smoothly until we hit a bump in the road when dealing with a particular page with some Vietnamese text. After some small (but not obvious) changes in configuration and more research than I cared to do on the subject of character sets, it's all working properly.
Read more →Creative use of temporary tables
At SiteCrafting, I enjoy working with a large number of different projects, each with their own requirements, technology, and problems to be solved, unfortunately, I sometimes forget about past solutions, until after I have finished writing a piece of code. Such is the case with a query that was eating up some serious processing time.
The problem was with a GROUP BY query with LEFT JOINs to several other tables and summing up totals from those joined tables. This query was taking about 4 minutes 45 seconds to run, and worse yet, it was affecting searches which had nothing to do with that query, and probably also eating up precious memory and cpu resources.
Read more →The fewer the queries the better
I always enjoy trying to do my work creating web applications using the fewest number of database queries possible. It's kind of a pride thing, I guess. That and I suppose it makes to improve an app's performance and reduce the load on a server. If you're into that kind of thing. ;)
A technique I use subtitutes the temptation of using queries whose results call queries and instead uses only two.
Read more →Making the timer look better
Last time, I outlined a way to create a simple PHP script timer. I use this timer in many of the projects that I work on, and it's really helpful to nail down trouble spots in scripts. The thing that it lacks, however, is a decent display. When you call the elapsed() function, it only gives you a number. Creating a decent display for each timer call is tedious and boring. So I simplified it. Now, I'm going to extend the existing Timer class and add some new functionality - make it look better and make it easier to call and display the information.
There's small choice in rotten apples.
Recently, I had a need to POST a form, using PHP script, to a remote url. As I started to research a solution, I soon realized there were very few limited options.
Read more →Code Soup versus Short Stories
On my way to meeting with a client, I got into a conversation about using functions in your code. One of the guys learned to write assembly first, and so his stance was that creating functions was only feasible when you used the same code more than (about) three times. That view makes a certain sense - don't deal with the overhead of creating tons of functions for stuff you'll seldom use.
I argue that you should use functions where ever possible, first because it makes code easier to generalize (and thus re-use), but also because it makes code much more readable.
Read more →Making Inserts Sucks
Why butter fingers break apps
header("Location: ...") function should pose no danger of messing up my app -- but today it did.