PHP WTF

February 15th, 2007

I love The Daily WTF, but live in fear I will write something worthy of it. However in anything, not just programming, brain fudge is somewhat inevitable. So here’s my latest:

class Admin_Controller extends h_Controller
{
 
	function __construct()
	{
                // parent::__construct(); originally here
                $form = new h_Form_Example();
		$this->processor = new h_Form_Processor($form);
		parent::__construct();
	}
 
	function GET()
	{
		echo $this->processor->display();
	}
 
	function POST()
	{
	}
 
}

This code work in progress. However if you look at the comment I added in the constructor, then you’ll see how it went wrong early on:

  1. The parent’s constructor calls the child’s GET or POST function as required, pertaining to the HTTP request.
  2. The constructor being called here meant that the child’s constructor couldn’t instantiate the member objects that will be used for the methods.
  3. Member didn’t have the object to work with

I suppose that’s a warning to not create magic behaviour in the constructor. Moving it solved the problem, but I’m going to clear things up by implementing the auto-behaviour in a dispatch method.

Comments are closed.