cool OOP-phenomena!

From: Date: Thu, 11 Jan 2001 09:55:17 +0000
Subject: cool OOP-phenomena!
Groups: php.general 
Request: Send a blank email to php-general+get-33949@lists.php.net to get a copy of this message
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; } } function print_name() { echo $this->name . "<br>"; } } class Basis_A extends Basis { var $name = "Basis_A"; } class Basis_B extends Basis { var $name = "Basis_B"; } $my_basis_1 = new Basis(); $my_basis_2 = new Basis("A"); $my_basis_3 = new Basis("B"); $my_basis_1->print_name(); $my_basis_2->print_name(); $my_basis_3->print_name(); ?> The point is, that the class morphs itself into another class in the constructor. Hope it helps someone, Moritz.

« previous php.general (#33949) next »