Let's begin with a small code snippet:

<code>

class A {
    function A( $selector ) {
        switch( $selector ) {
            case 1: $obj = new A_1(); break;
            case 2: $obj = new A_2(); break;
            ...
        }
        $this = $obj;
    }
}

class A_1 {
    ...
}

class A_2 {
    ...
}

$a = new A(1); // $a is now an instance of A_1
$a = new A(2); // $a is now an instance of A_2

</code>

I use this trick to implement "polymorphic" objects.
I just wanted to know what other people think about
it.
Is this a "dangerous" technique? (i.e. changes in php
object model can break programs that use it)
Is it already in common use?
Any opinion is welcome.

Thanks

fbv


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

Reply via email to