Tuesday, July 21st, 2009

Use Registry To Remember Objects (So You Don’t Have To)

One of the biggest challenges in OOP programming with PHP is the ability to pass around objects and let other objects use them. This challenge can be solved with careful design, however. Here we will discuss the registry pattern, not a member of the GoF’s original patterns but still an important pattern nonetheless.
(more…)

Friday, July 17th, 2009

Where Multiple Levels Of Inheritance Will Kill You

One of the best features of PHP’s object model (and really all object models) is the concept of inheritance – that is, derived classes inherit the members and methods of their parents. This is a fantastic way to further encapsulate and abstract your code because it means you can define some base functionality and then later on extend that class to add new functionality and even override existing functionality to make the class specific.

But this concept is a double-edged sword in PHP (and all other languages). Here’s where multiple inheritances can kill you.
(more…)

Monday, July 13th, 2009

Superglobals In Classes: Revisited

Last December, I wrote about the use of PHP superglobals inside of classes (link here). I asserted at the time that superglobals inside of a class violated some basic rules on what a class was supposed to do. Today, I am revisiting that discussion.
(more…)

Sunday, July 5th, 2009

Installing PHP 5.3 On Ubuntu

With the release of PHP 5.3 to the world, I wanted to be one of the first to try it. The problem is that the typical package managers for Ubuntu won’t include PHP 5.3 for some time – perhaps as long as a year. This is a problem, since I really want to try PHP’s latest and greatest features for myself.

The problem is, there seems to be a lack of clear, coherent instructions online about compiling PHP on Ubuntu from source. Either it’s so insanely simple that anyone who does it figures everyone else knows how, or everyone relies on the pre-built binaries released by the world that any time I search for “Ubuntu PHP source” I get “why don’t you just use the built-in package manager?” And so, I wanted to write a set of instructions for how I configured and compiled PHP, on Ubuntu Jaunty.

For the most part we’ll use standard out-of-the-box packages that Ubuntu provides. Since the features I’m looking for are in PHP 5.3, I’m fine with having slightly outdated packages for other software as long as they’re compatible with PHP 5.3.
(more…)

Monday, December 22nd, 2008

Searching Arrays for Values

Sometimes I have to check an array for the existence of a value; for example, I may want to parse an array for a value and then include (or exclude) that value fro an SQL query. I quickly found out that using in_array() is slower than using isset(). For example:
(more…)

6:56 pm | Comment (3) | Categories: General PHP, PHP 5
Newer Entries »