Re: OOP, dynamic class extention
| From: | Jackson Miller | Date: | Thu, 30 Oct 2003 20:34:48 +0000 |
| Subject: | Re: OOP, dynamic class extention | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-168180@lists.php.net to get a copy of this message | ||
On Thursday 30 October 2003 02:15 pm, Marek Kilimajer wrote:
> Can you show it once again. In your first email you use a constant, not
> variable.
Sure. In my first email I said that I had tried with a variable too (but
didn't show the code).
Ex1 gives a "cannot inherit from undefined class" error
Ex2 gives a "parse error, expecting T_STRING"
Ex1 (with constants):
<?php
// settings to be set on install of the app
define("MY_BASE_CLASS","base_class");
define("MY_BASE_CLASSFILE","base_class.php");
// require the class file
require_once(MY_BASE_CLASSFILE);
class my_child_class extends MY_BASE_CLASS {
// yada yada
}
?>
Ex2 (with variables):
<?php
// settings to be set on install of the app
define("MY_BASE_CLASS","base_class");
define("MY_BASE_CLASSFILE","base_class.php");
$my_base_class_var = MY_BASE_CLASS;
// require the class file
require_once(MY_BASE_CLASSFILE);
class my_child_class extends $my_base_class_var {
// yada yada
}
?>
Also, just to be clear:
base_class.php
<?php
class base_class {
function base_class() {
echo "it works";
return true;
}
}
?>