title: CodeIgniter base classes, why is that?
body: <p>A lot of frameworks out there decided to use this approach: force the user to extend a base controller class (if you want to create a new controller) or to extends a base model class (if you want to create a new model).</p>
  
  <p>Let's take a look at the code of CodeIgniter's controller base class:</p>
  
  <pre><code>/**
   * Constructor
   */
  public function __construct()
  {
      self::$instance =&amp; $this;
  
      // Assign all the class objects that were instantiated by the
      // bootstrap file (CodeIgniter.php) to local class variables
      // so that CI can run as one big super object.
      foreach (is_loaded() as $var =&gt; $class)
      {
          $this-&gt;$var =&amp; load_class($class);
      }
      $this-&gt;load =&amp; load_class('Loader', 'core');
  
      $this-&gt;load-&gt;initialize();
  
      log_message('debug', "Controller Class Initialized");
  }
  </code></pre>
  
  <p>What does it do? Well, as far as I can see, it just allows us to use <code>$this-&gt;load-&gt;...</code> for example. </p>
  
  <p>Let's take a look at the <code>__get()</code> magic method of the model base class:</p>
  
  <pre><code>/**
   * __get
   *
   * Allows models to access CI's loaded classes using the same
   * syntax as controllers.
   *
   * @param   string
   * @access private
   */
  function __get($key)
  {
      $CI =&amp; get_instance();
      return $CI-&gt;$key;
  }
  </code></pre>
  
  <p>It does exactly the same thing. Now what does this way of doing things bring?</p>
  
  <p><strong>PRO</strong></p>
  
  <ul>
  <li>You can access useful CI classes by <code>$this-&gt;...</code>.</li>
  </ul>
  
  <p><strong>CONS</strong></p>
  
  <ul>
  <li>You have to force the user to extends the base class</li>
  <li>You have to force the user to call the <code>parent::__construct()</code> in the class construct</li>
  <li><code>get_instace()</code> is reserved</li>
  <li><code>$this-&gt;instance</code> redefinition cause a fatal error</li>
  <li>You have basically repeated the same code both in the Model base class and the Controller base class</li>
  </ul>
  
  <p>Now let's take a look at another approach:</p>
  
  <p>Create a static class, such as <code>App</code> that do all the things the base controller does:
  For example,  <code>$this-&gt;load-&gt;...</code> would be <code>App::load-&gt;...</code>.</p>
  
  <p>Now consider pros and cons again:</p>
  
  <p><strong>PRO</strong></p>
  
  <ul>
  <li>You can access useful CI classes by <code>App::...</code>.</li>
  <li>You <strong>don't</strong> have to force the user to extends the base class</li>
  <li>You <strong>don't</strong> have to force the user to call the <code>parent::__construct()</code> in the class construct</li>
  <li><strong>no</strong> methods name or properties name are reserved</li>
  <li>You can use App both in the Model and in the Controller</li>
  </ul>
  
  <p><strong>CONS</strong></p>
  
  <ul>
  <li>You have no more the <code>$this-&gt;</code> sexy syntax???</li>
  </ul>
  
  <p><strong>QUESTION</strong></p>
  
  <p>Here it comes the real question: would be the second a better or worse approach compared to the CI one? Why?</p>