assigning objects
| From: | David P. Schwartz | Date: | Tue, 14 Nov 2000 23:12:56 +0000 |
| Subject: | assigning objects | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25270@lists.php.net to get a copy of this message | ||
If I have a class that is used to represent a row in a db-table, defined thusly:
class mytable
{
var $fld1, $fld2, $fld3;
:
:
function select_db( $where_str )
{
:
$result = mysql_query( blah-blah );
if ($result)
$obj = mysql_fetch_object( $result );
$this = $obj; // does not work!
}
}
Is there any way to assign the $obj values to corresponding $this vars, other
than saying:
$this->fld1 = $obj->fld1;
$this->fld2 = $obj->fld2;
$this->fld3 = $obj->fld3;
In c++ this would be accomplished with a copy constructor which, for most simple
cases like this, is implicitly defined.
Thanks
-David