Moritz Petersen wrote:
>
> Hi list,
>
> this is not a problem, but a nice feature of OOP, I found today. Maybe it is
> useful for someone:
>
> <?php
> // class test
>
> class Basis
> {
> var $name = "Basis";
>
> function Basis($typ = false)
> {
> switch ($typ)
> {
> case "A":
> $this = new Basis_A();
> break;
>
> case "B":
> $this = new Basis_B();
> break;
> }
> }
> The point is, that the class morphs itself into another class in the
> constructor.
>
> Hope it helps someone,
My idea would be to do the following:
check if file $path_to_includes/$prefix$typ$postfix if file exists
include_once that file and create an object of that type $this = new
$typ();
Thus you get away from the switch case which you have to change for
every new class you add to the inheritance tree. I've used this
technique a few times, and I also think I've seen this used in some
database wrapper classes.
--
Paul K Egell-Johnsen
Utvikler/PR Manager
eZ systems as
http://ez.no/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]