Re: [PHP] OOP, dynamic class extention

From: Jackson Miller (jackson_at_coldfeetcreative.com)
Date: 10/30/03


To: Marek Kilimajer <kilimajer@webglobe.sk>
Date: Thu, 30 Oct 2003 13:21:12 -0600

On Thursday 30 October 2003 12:29 pm, Marek Kilimajer wrote:
> php is not c, you can't use constants this way.
but why? Is there a work around?

-Jackson

>
> Jackson Miller wrote:
> > I want to be able to set a base class in a settings file, and then have
> > other classes extend the base class, but PHP won't let me do what I have
> > tried.
> >
> > I get the following error:
> > Fatal error: Class cepweb: Cannot inherit from undefined class
> > my_base_class in /home/me/my_child_class.php on line 10
> >
> > ex:
> > <?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_CLASSFILE {
> > // yada yada
> > }
> > ?>
> >
> > Any thoughts on ways to overcome this?
> >
> > I have tried using a variable instead of a constant, but it didn't work.
> >
> > -Jackson



Relevant Pages

  • Re: Opinions / Votes Needed
    ... need added in to PHP 6, ... If you really *need* to used a staticly typed language then don't use PHP, ... A base class type which all objects automagically extend, ... Thoughts, Opinions, Votes? ...
    (php.general)
  • What mechanism may be used in PHP that will act as #define and #ifndef
    ... The question is I have a base class in file1 and files file2 and file3 ... <?PHP ...
    (comp.lang.php)
  • OOP, dynamic class extention
    ... I want to be able to set a base class in a settings file, ... but PHP won't let me do what I have tried. ... Fatal error: Class cepweb: Cannot inherit from undefined class my_base_class ...
    (php.general)
  • Re: [PHP] OOP, dynamic class extention
    ... Jackson Miller wrote: ... > I want to be able to set a base class in a settings file, ... > classes extend the base class, but PHP won't let me do what I have tried. ...
    (php.general)
  • Re: What mechanism may be used in PHP that will act as #define and #ifndef
    ... both contain classes that derive from the base class in file1. ... <?PHP ... wrapping the base class definition in a conditional because I thought ... I remember reading that PHP uses the same scope rules as C and C++. ...
    (comp.lang.php)