Q:

Is there any option for dynamical extension of class in PHP?

What I meant is to change the base class for a derived class dynamically. For example there are two classes B1 and B2. When I run a php script with parameter class=b1, a class (say class D) defined in that script should extend class B1 else if parameter is class=b2 it should extend B2. 
Expect something like this
class B1{
    // some codes 
}

class B2{
    // some codes 
}

switch($_GET['class']){
   case 'b1': $baseclass = "B1"; break;
   case 'b2': $baseclass = "B2"; break;
}

class D extends $baseclass{
    // some codes 
}

Is there any option in PHP like that? Please suggest me if any option is available. 
Thanks in advance.

A:

I would not suggest to dynamically extends classes. Although it is possible it is a really bad design that will have many unwanted side effects. To tell at least one: How will you generate an API documentation for that class(es)? (Knowing this is the smallest problem)
With the additional info from the comments: you want to build something like a ORM that can work with different databases, I was thinking first about PDO. It allows to access a large set of databases using the same interface.
If you for whatever reason need a non PDO solution you could make a design like this:
<?php

class DatabaseStorage {

    /**
     * @var DB_Mysql|DB_SQLite|DB_Postgres ...
     */
    protected $database;

    /**
     * @param DB_Mysql|DB_SQLite|DB_Postgres ... The inner database to be used
     */
    public function __construct($database) {
        $this->database = $database;
    }

    /**
     *  Connect to the database
     */
    public function connect($host, $user, $password) {
        $this->database->connect($host, $user, $password);
    }

    /**
     * Query the database
     */
    public function query($query) {
        return $this->database->query($query);
    }

    // other methods may follow
}

Then use the class like this:
$databaseType =$_GET['databaseType'];

// you should check the value before using it!!
/*if(!is_valid_database_type($databaseType)) {
    die('BAD input');
}*/

$databaseClass = 'Database' . $databaseType;
$database = new $databaseClass();

// use $database as argument to the storage constructor
$storage = new DatabaseStorage($database);

However this is just an example. You'll find other ways to prevent from dynamic code generation,

