Date: 11/06/99
- Next message: php-dev <email protected>: "[PHP-DEV] PHP 3.0 Bug Summary Report"
- Previous message: Thies C. Arntzen: "Re: [PHP-DEV] Change User on a pconnect"
- In reply to: ZeroDiVide: "Re: [PHP-DEV] PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers"
- Next in thread: ZeroDiVide: "Re: [PHP-DEV] PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers"
- Reply: ZeroDiVide: "Re: [PHP-DEV] PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
You should use the Factory design pattern I suppose. How about the following:
class DB {
function Factory($driver) {
switch( $driver ) {
case 'mysql':
return new Mysql_Db();
case 'oracle':
return new Oracle_Db();
default:
return new Dummy_Db();
}
}
}
And then do something like (actually it doesn't even need to be
$new_db = DB::Factory('mysql');
Andi
At 10:49 AM 11/6/99 -0600, ZeroDiVide wrote:
>So how do i do polymorphisim in php?
>
>What'd i'd like to do :
>class Db {
> Function Db( $driver ) {
> switch( $driver ) {
> case 'mysql':
> return new Mysql_Db();
> case 'oracle':
> return new Oracle_Db();
> default:
> return new Dummy_Db();
> }
> }
>
>This is so i can achive a rough equivelence class with dbi :: dbd.
>
>$new_db = new Db( 'mysql' );
>
>---------------------------------------------------------------------------
>-----
>| Jason "ZeroDiVide" Orcutt "Code is life is
>Code" |
>| Prometheus Project -
>http://prometheus.zerodivide.net |
>---------------------------------------------------------------------------
>-----
>
>On 6 Nov 1999, Bug Database wrote:
>
> > ID: 2675
> > Updated by: andi
> > Reported By: zerodiv <email protected>
> > Status: Closed
> > Bug Type: Other
> > Assigned To:
> > Comments:
> >
> > This is not a bug. You are misusing constructors. What the new operator
> does is similar to C++. It first allocates memory for the object and then
> calls the objects constructor. The constructor does not have a return
> value and returning something from it is pointless. When you're calling
> new Bar(); you're telling PHP you want a new object of type Bar and not
> foo. Maybe what you want is inheritence?
> >
> > Full Bug description available at: http://bugs.php.net/version4/?id=2675
> >
> >
> > --
> > PHP Development Mailing List <http://www.php.net/>
> > To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
> > For additional commands, e-mail: php-dev-help <email protected>
> > To contact the list administrators, e-mail: php-list-admin <email protected>
> >
>
>
>--
>PHP Development Mailing List <http://www.php.net/>
>To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
>For additional commands, e-mail: php-dev-help <email protected>
>To contact the list administrators, e-mail: php-list-admin <email protected>
--- Andi Gutmans <andi <email protected>> http://www.zend.com/-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: php-dev <email protected>: "[PHP-DEV] PHP 3.0 Bug Summary Report"
- Previous message: Thies C. Arntzen: "Re: [PHP-DEV] Change User on a pconnect"
- In reply to: ZeroDiVide: "Re: [PHP-DEV] PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers"
- Next in thread: ZeroDiVide: "Re: [PHP-DEV] PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers"
- Reply: ZeroDiVide: "Re: [PHP-DEV] PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

