Re: DB_DataObject - problem with inheritance
| From: | mitchell perilstein | Date: | Sat, 27 Dec 2003 13:18:36 +0000 |
| Subject: | Re: DB_DataObject - problem with inheritance | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-9842@lists.php.net to get a copy of this message | ||
It's in there. In your config.ini file, do something like this
extends = MyBase
extends_location = MyBase.php
This specifies an intermediate class which inherits from DB_DataObject and which all your classes will be subclasses of. It can contain the common functionality you wanted:
class MyBase extends DB_DataObject {
function toHtml () { return $this->id ; }
}
Then your classes will be automatically generated like this:
class DataObject_Person extends MyBase { ... }
class DataObject_Place extends MyBase { ... }
and you can do this:
$person = new DatatObject_Person;
$person->get(444);
echo $person->toHtml(); // ---> "444"Hth, happy and merry, mitch Torsten Roehr wrote:
Hi, I just read the DB_DataObject documentation and wondered about the following. If I create a DataObject class for all my tables and use those as my application objects (e.g. DataObjects_Person is my Person class), I've got no possibility to inherit from other classes (for example extend a Base class with basic functionality for all classes) because of PHP4's inheritance limitation. How do you guys get around this? Big thanks in advance, Torsten Roehr