Re: Copying an Object

From: Date: Wed, 22 Sep 2010 15:22:17 +0000
Subject: Re: Copying an Object
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-308257@lists.php.net to get a copy of this message
Am 22.09.2010 13:35, schrieb Daniel Kolbo:
Hello PHPers, I have: class A { ...code } class B extends A { ...code } $a = new A(); $b = new B(); I would like to get all of the properties of $a into $b by value. Class A extends 3 other classes. I would like a way to not have to manage a 'copy' method in B if A or one of the subclasses of A change. I was reading about clone, but this doesn't really seem to help me in this situation. How can I copy $a into $b? Thanks, dK ` Hi dk,
by using inheritance only you will bind your code to an specific implementation of code. Wherever you want to do with your classes, i think is the better way to use some design patterns to build classes by the functionality or by structure. The use of composition allow to manage your classes flexible very well. But look for Factory or Decorator (maybe Command in this case) to solve the class inheritance. Regards Carlos Medina

« previous php.general (#308257) next »