note 9356 added to Classes and Objects
| From: | mark at cynergic dot net | Date: | Sat, 28 Oct 2000 21:04:15 +0000 |
| Subject: | note 9356 added to Classes and Objects | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7163@lists.php.net to get a copy of this message | ||
How about adding variable class extensions.
ie: Class MyClass extends $AnotherClass {
This would make (for example) changing database interfaces easier at the abstraction level without
the need to directly edit the class code.
I have a kludge thats works (but is Uggh!) like this:
if(!$DB_BASE) DB_BASE = 'db_mysql.class'; /* Sets default if not set higher up class chain
*/
/* Note: I do not use include_once here because I wish to allow runtime changes to be made. */
/* eg: I am using an oracle interface class with a DBO class object to perform some selects */
/* I then wish to use another DBO object - extending the mysql interface class - to take that */
/* data and perform some insertions. ie: to move data between an oracle and a mysql database. */
/* I can set up two top level classes called 'dbo_oracle' and 'dbo_mysql' each
extending upon */
/* the dbo class this way. each of these classes would have an appropriate line such as: */
/* if (!$CLASS_ID('DBO:mysql.class') include the class etc. */
if (!$CLASS_ID['DB_BASE']) {
include($CLASS_PATH.$DB_BASE);
if (!$CLASS_ID['DB_BASE']) {
trigger_error("002::SYSTEM::DBO Class",FATAL);
}
}
$CLASS_ID['DBO:'.$DB_BASE] = true;
eval("class DBO_".." extends $DB_BASE
{".implode("\n",file($PHP_INCLUDE_PATH.$CLASS_PATH.'dbo.internals'))."}");
http://www.php.net/manual/language.oop.php