[PHP] OOP, dynamic class extention

2003-10-30 Thread Jackson Miller
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Jough Jeaux
Shouldn't this line:
class my_child_class extends MY_BASE_CLASSFILE {

Read like this:
class my_child_class extends MY_BASE_CLASS {
 
After all base_class.php isn't the name of your class, base_class is.

Jackson Miller [EMAIL PROTECTED] 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:

// 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears

Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Marek Kilimajer
php is not c, you can't use constants this way.

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Jackson Miller
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Marek Kilimajer
Why? I guess because php is interpreted language and is parsed only 
once, no preprocessor. Workaround is quite easy, use variable:

?php

// settings to be set on install of the app
$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
}
?
Jackson Miller wrote:
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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Jackson Miller
On Thursday 30 October 2003 01:27 pm, Marek Kilimajer wrote:
 Why? I guess because php is interpreted language and is parsed only
 once, no preprocessor. Workaround is quite easy, use variable:

I thought that too, and tried it before posting to the list (it was at the 
bottom of my first email).

Unfortunately when you do that you get and expecting T_STRING error.  The same 
thing happens if you put the var in quotes.

Why would it not parse the constant the first time?  It does everywhere else.

-Jackson



 ?php

 // settings to be set on install of the app
 $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
 }
 ?

 Jackson Miller wrote:
  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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Marek Kilimajer
Jackson Miller wrote:
On Thursday 30 October 2003 01:27 pm, Marek Kilimajer wrote:

Why? I guess because php is interpreted language and is parsed only
once, no preprocessor. Workaround is quite easy, use variable:


I thought that too, and tried it before posting to the list (it was at the 
bottom of my first email).
Can you show it once again. In your first email you use a constant, not 
variable.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Jackson Miller
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;
}
}
?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP, dynamic class extention

2003-10-30 Thread Boyan Nedkov
Hey guys, you can extend a _class_ from an existing _class_ but not from 
a _string_constant_ (Ex1 - MY_BASE_CLASS is evaluated to constant of 
type string) neither from a _string_variable_ (Ex2 - $my_base_class_var 
is a variable of type string).

To be able to use different base classes with the same name just change 
the reference to the different settings files that contain the class 
declared with the same name but with different functionality, perhaps in 
the following way:

?php
  $a = 1;
  // blah blah
  if ($a==1) {
include_once(settingsfile1.php);
  } else {
inclide_once(settingsfile2.php);
  }
?
Or even (much) better create a single base class in a single 
configuration file and different modified instances of that class used 
for each of the different configurations you may have.

Boyan



Jackson Miller wrote:

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;
}
}
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php