SEO guidelines

Submit your site to the major search engines for indexing: Check that your robots.txt file is correct and not preventing crawlers from getting into your site: Use Video and Flash sparingly, and knowing it doesn’t get indexed by crawlers Promote important content to home page, and make sure there are clean […]

Design patterns: singletons

Singleton classes basically mean there is only one object class of a certain type running at all times. That could be used to store Global variables, for example. The way to implement it on PHP: class Preferences {     private $props = array();     private static $instance;     private function __construct() { }  // By […]

Design patterns: Composition and Inheritance (Strategy pattern)

Instead of creating child classes, you create a new tree of classes and move some of the functionality away from the main tree. You connect the trees via object creation, meaning some of the classes in one tree contrain objects with the other classes type. The advantage is that the trees are more specialized in […]

PHP Error handling

When there are problems, always return an Exception object to the client. Exception constructor accepts two optional arguments: an error string (error description in “plain english”) and an error code. These are the Exception object’s public methods available: getMessage() – Get the message string that was passed to the constructor. getCode() – Get the code […]

PHP interfaces

Interfaces are pure class templates that define functionality. It can contain properties and methods, but no method implementation. See the example below: interface Chargeable {     public function getPrice(); } So any class that implements this interface, will look something like this: class ShopProduct implements Chargeable {     // …     public function getPrice() { […]

OOP Best Practices and architecture

When creating classes, make a really general abstaction of the object you have in mind (usually an abstact class or interface), and then start working your way down to the specifics using inheritance, encapsulation and polymorphism. For example: to create a book object for an ecommerce site, create something like Product / Item / Books / […]