Q:

Howto refactor growing class in php?

I have a class that's growing past overview. It's the engine of a framework doing db, blob, file operations and more.
The class is being used heavily from different components and I don't want to refactor the monolithe into sub-classes since too much code around it would break.
I could live with 
class engine {
  include 'core/db.php';
  include 'core/blob.php';
  include 'core/profiler.php';

  function __construct($config..) {
  }
}

with core/db.php containing methods as in
<?php
function dbPrepare($sql,$args) {
  ...
} 
...

I could live with the result, but PHP won't let me throw in an include where it expects a function.
Any solution for this? (I've touched the idea of letting the engine rebuild itself based on changes in sub-components but discarded the mess).

A:

Use traits to assemble your class. Basically you declare the traits one per file as such
core/db.php
trait Db
{
    public function dbPrepare($sql, $args)
    {
        // ...
    }

    public function dbSomethingElse() 
    {
        // ...
    }
}

core/blob.php
trait Blob
{
    public function blobMeBabyOneMoreTime()
    {
        // ...
    }
}

And then assemble them in your main file (engine.php)
require 'core/db.php';
require 'core/blob.php';

class engine {
    use Db;
    use Blob;
}

PS: You should look into autoloading and namespaces and avoid including files manually.

