PHP5 Date Iterator

I’ve recently had cause to iterate through ranges of dates, either Weekly, Monthly or Daily and for some reason there isn’t really a good default way to do this. So I wrote my own. This is a pretty basic implementation of an iterator but it serves its without too much fuss.

class Date_Iterator implements Iterator {
	private $increment;
	private $startDate;
	private $endDate;
	private $currentDate;
	private $iterations = 0;
	 * @param string $increment Anything that strtotime can understand. eg. day, week, month, year
	 * @param int|string $startDate
	 * @param int|string $endDate
	 * @return 
	function __construct($increment, $startDate, $endDate) {
		$this->increment = $increment;
		if(is_int($startDate)) {
			$this->startDate = $startDate;
		} else {
			$this->startDate = strtotime($startDate);
		if(is_int($endDate)) {
			$this->endDate = $endDate;
		} else {
			$this->endDate = strtotime($endDate);	
		$this->currentDate = $this->startDate;
	function current() {
		return date("d-M-Y", $this->currentDate);
	function next() {
		$current = date("d-M-Y", $this->currentDate);
		$this->currentDate = strtotime($current." + 1 ".$this->increment);
		$this->iterations ++;
	function valid() {
		return $this->currentDate < = $this->endDate;
	function rewind() {
		$this->currentDate = $this->startDate;
	function key() {
		return $this->iterations;

My Computer Setup

I get a few questions from people asking why I use Windows Vista and not Ubuntu – I’m pretty confident using Linux and I my desktop (that I’m not using) is set up with Ubuntu. It’s a matter of personal preference, but one of the biggest reasons is it’s tablet support. I haven’t even tried using Ubuntu on this machine as I have no desire – I really think the tablet support works really well. What’s more is I really like Office 2007, the new interface takes a lot of getting used to but it does provide the interface that you need when you need it. Anyway I thought I would outline the other stuff I have installed on my machine, in roundabout order of time I spend using them.

  1. Firefox 3
    1. Firebug 1.2
    2. Prism (This is how I access GMail and Google Reader)
    3. FirePHP
  2. Eclipse
    1. PHP Development Tools
    2. Subversive
    3. JSEclipse
    4. PYDev
    5. SQL Explorer (I’ve just installed this to work on some fairly complex SQL stuff)
  3. Putty
  4. Pidgin
  5. WAMP Server
  6. Songbird (I’ve recently replaced iTunes with Songbird)
  7. Filezilla
  8. Notepad 2 (I’m seriously considering replacing this with OpenKomodo)
  9. Office 2007 (with OneNote)
  10. Firefox 2
    1. Firebug 1.0
  11. Tortoise SVN
  12. Skype

There’s a couple of important things to note about this setup, I would love to be rid of Firefox 2, Firefox 3 is so much better, however Firebug 1.2 beta really doesn’t cut it. It is certainly a lot better than it was, but I’m really hanging out for it to get a bit more stable. I think it causes a few memory leaks as well which doesn’t really help, especially when you are using Firefox all day with 20-30 tabs open.

JSEclipse is the best free/open source Javascript plugin for Eclipse. It was bought by Adobe quite some time ago and used to power the Flex development environent then they seem to have dropped development on it, it’s a little bit sad really.

I really hate the fact that I have Skype even installed on my machine, but as many people that are using Jabber/Google Talk it doesn’t even compare to the amount using Skype. I could probably get away with using Pidgin all the time, but it doesn’t support voice. It certainly looks to me as though voice support is coming, hopefully soon than later. My biggest problem with Skype is the overly closed nature of the protocol, 3rd party implementations can’t even connect to the IM service.

Silverstripe: as a platform

At Xebidy we use Silverstripe almost exclusively as a platform to build upon. Not just Bootstrap (our custom extensions) but also the Sapphire framework to build the more advanced parts of the website we build. The Sapphire framework is at the most basic level an MVC framework for PHP5 with a number of additions to service the Silverstripe CMS. I’m writing here a breakdown of what I see as strengths and weaknesses of the platform. Before you read on please take these 2 points into consideration, I really do like working with it and I have a lot of time invested into the platform and this is my opinion and not that of my employer.

I would love to hear everyone’s opinion on this so drop me an email or leave a comment.

  1. Abstraction of layers

    Over the past few releases there has been talk on the Silverstripe forums, their trac and the mailing list of trying to move the CMS code away from the core of the MVC framework so normal non-CMS based applications don’t need to rely on it. While it is a little frustrating currently over the past couple of releases this has progressively gotten better and I believe that this can be achieved in the near future. The specific example of this is ContentController which I would suggest should be refactored out into a SiteTree_Controller and ContentController.

  2. Extensions/Decorators

    This is probably what I love the most about this platform and I think the guys over at Silverstripe should be applauded for this. They have built an awesome framework wherein each Class can be extended quite simply. The beauty of this is in it’s simplicity for the developer and it really allows for extensible applications to be built. It definitely has a few bugs in it which can be quite tricky to track down but generally it behaves exactly how you expect it to. My biggest suggestion for Silverstripe is to push this as a strength of the platform because it really is very cool and extremely functional.

  3. Template Engine

    Most people that are new to the the platform are opposed to Silverstripe having it’s own templating system. It definitely has it’s pros and cons. Firstly it is not a fully blown parser, relying on a number of regexes to parse it’s syntax. I run into this problem quite regularly and end up nesting control blocks or creating methods on objects that in my opinion should be handled in the presentation layer. The second problem I have with it is it’s lack of a context stack – this means you can’t access something in the previous nested control block or even access a variable (not really variables) in the “global” context.

    Don’t get me wrong, it’s not all bad and I don’t believe that there is anything in this that can’t be fixed (I started writing a new parser for it quite some time ago). On the flip-side the way the templating engine matches the Model of the application is a really elegant solution and I don’t believe the template engine should be removed. A cool but definitely complex improvement for this would be to make it more pluggable and allow extensions to expand the language.

  4. Documentation

    Generally the documentation on the project is very good. I think it could be improved with some more articles about the lower levels of the framework and have them highlighted on the blog rather than the rather boring marketing that is currently posted on it. Similarly the PHPDoc documentation on the framework is generally awesome and really helps with the code completion within Eclipse but this can definitely be taken from good to excellent by having protected and public variables types being documented. (As an aside I would love a way to document all the magic variables that are created by Framworks such as this.)

  5. Communication

    The Silverstripe project is coming from a different position than many open source projects in that it was released as open source and that company continues to drive the majority of the development. This is great and I definitely appreciate it. Many of the decisions made about the framework and it’s directions are made behind closed doors. This prevents any buy in from external developers. A great example of this was recently a decision was clearly made by the Silverstripe guys and then presented to the dev list for ‘opinions’. This work has been going on quietly on 2 branches with nary a word on how the progress is going. Similarly the 2.2.2 release has recently been completed and in the lead-up there was very little communication regarding the plans and goals of the release.

Function Overloading in PHP

Update: I have written about a more Java-like, argument based overloading solution here.

I’ve been trying to get a set of good basic functions included within my PHP framework and ran across a nice little trick to allow function (without a class) overloading, the code should speak for itself.

This will be the default file.

if(!function_exists("overloadableFunc") ) {
  function overloadableFunc() {
    echo "foo";

and this will be in the overloading file (needs to be included before the default.

function overoadableFunc() {
  echo "foobar";