Hi all,

Say you may want to create an instance in multiple ways, such as creating
from scratch or loading from a database. Is something like this normal for
creating an instance?

class Foo
{
  function Foo($method)
  {
    switch ($method) {
      default:
        $method = 'create';
      case 'create':
      case 'load':
        $args = func_get_args();
        array_shift($args);
        if (!call_user_func_array(array(&$this, $method), $args)) {
          $this = false;
        }
    }
  }

  function create()
    ... // Returns false on failure; true otherwise.

  function load($id)
    ... // Returns false on failure; true otherwise.

  function save()
    ... // Saves to database.

}

What are other people doing to instantiate their objects?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to