Re: Re: [PEPr] Proposal for Database::DB_Table

From: Date: Wed, 07 Jan 2004 17:07:56 +0000
Subject: Re: Re: [PEPr] Proposal for Database::DB_Table
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-24867@lists.php.net to get a copy of this message
Hi Paul, I have amended your class mid-quote to show how you can do what you need quite simply. However, you need not use the factory pattern here. PEAR_PackageFileManager simply uses a method called setOptions() to act as the real constructor, and allow the return of PEAR_Errors. Incidentally, I've completed code for a new Error raising class based on an Error Stack that would obsolete any need for stupid non-constructor constructors. It would also allow raising multiple error conditions in the same method. The thing also does everything that Error_Raise and Error_Handler did in 500 lines. When I've done some serious testing and tweaking, I will propose it for inclusion in the core. Naturally, it is not going to catch a PEAR_Error (PEAR_Error is not exactly forward compatible with an error stack concept), but it can raise PEAR_Errors to be backwards compatible with older packages. $a = &new DB_Table($dumbdb, 'mytable'); if (Error_Stack::hasErrors()) {
     // process the errors
} Greg Paul M Jones wrote:
This is to illustrate what I mean about factory methods and direct extension: <?php class alpha {
    function &Factory($args, $classname = 'alpha')
    {
        // do stuff
        return new $classname($args);
    }
        function __construct($args)
    {
        // do stuff
    }
} class bravo extends alpha {
    function __construct($args)
    {
        // do other stuff
    }
          function &Factory($args, $classname = 'bravo')
      {
          $x = &parent::Factory($args, $classname);
          return $x;
      }
} // returns an 'alpha' object, not a 'bravo' $bravo =& bravo::Factory($args); // returns a 'bravo' object $bravo =& bravo::Factory($args, 'bravo'); ?>


« previous php.pear.dev (#24867) next »