Archive for the ‘PHP’ Category

Common misconceptions in web application development

Sunday, July 20th, 2008

Over the time I have developed for the web, I have read and heard many assumptions about development practices and technologies. This is my list of common misconceptions in (web) development:

1. OO code is less performant than procedural code

The number one argument against OO application design from procedural advocates. This argument is based more on intuition than fact. The usual examples pit short procedural code against equivalent OO code in which procedural code comes out triumphant as more terse and performant.
(more...)

Handling mail and mime in PHP using the Zend Framework

Friday, July 18th, 2008

Handling mail is a very common requirement in web applications. Even the most basic sites usually have a contact form that sends a mail through the server instead of putting a contact mail address for spam-spiders to find. Using PHP's built in function (aptly named mail() ) is relatively straightforward - until you need slightly more advanced features, such as adding and encoding email headers or sending multiple mails efficiently.
(more...)

The Advancing PHP Developer Part 5: Design Patterns

Saturday, July 12th, 2008

5. Design Patterns

A design pattern is a general reusable solution to a recurring design problem in object-oriented systems. Design patterns are essentially blueprints that suggest how to solve a particular set of OO design problems while adhering to OO best good-practices (which I've recounted in my Object Oriented part of this series).

To explain by example, lets have a look at the Model-View-Controller pattern, a common pattern in use on the web and a source of much confusion amongst aspiring developers. The Model-View-Controller pattern (abbr. MVC) is a general solution for decoupling domain logic from the user interface, resulting in much better maintainability for both.
(more...)

Operator overloading in PHP

Tuesday, July 8th, 2008

Operator overloading is a programming language features that allows operators to act differently depending on the type of data they are operating on. Since OOP lets us create custom types (classes), there are plenty of opportunities to do useful and interesting code manipulations using operator overloading.
(more...)

Passing arrays to Zend_Controller_Router

Monday, June 23rd, 2008

WARNING: The following contains unsanctioned HACKS to the Zend Framework. Use at your own discretion.

A big advantage to using the front controller in the Zend Framework is the ability to create nicely formatted urls. Instead of an ugly GET string we can pass parameters as slash delimited key -> value pairs. For example:
www.techfounder.com/index.php?post=passing_arrays&comment=3 can be replaced with www.techfounder.com/post/passing_arrays/comment/3
(On techfounder this is actually performed via mod_rewrite rules, but the principle is the same).

The implementation of the default router in the Zend Framework (Zend_Controller_Router_Rewrite) does not allow for passing arrays in this manner though, since previously set keys get overwritten if they are declared more than once. This is somewhere between semi-annoying to very annoying, so lets get straight to hacking it into submission.
(more...)