Re: PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers

From: Date: Sat, 06 Nov 1999 16:49:19 +0000
Subject: Re: PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-12171@lists.php.net to get a copy of this message
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@zerodivide.net > 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@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.dev (#12171) next »