problems with includes and extending classes
| From: | Chris Jackson | Date: | Mon, 14 Jan 2002 20:37:08 +0000 |
| Subject: | problems with includes and extending classes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-80491@lists.php.net to get a copy of this message | ||
I can't figure this one out...
I boiled it down to a test case where I have a bunch of classes and a
demo program:
demo.php:
===========================
<?
require_once "L.php";
$l = new L();
?>
===========================
L.php
===========================
<?
require_once "P.php";
require_once "C2.php";
class L extends P{
var $class = "L class";
var $c;
function L() {
$this->c = new C2();
echo "L init\n";
}
}
?>
=========================
<?
class P {
var $class = "P class";
function P() {
echo "P init\n";
}
}
?>
============================
C2.php
============================
<?
class C2 extends L{
var $class = "C2 class";
function C2(){
echo "C2 init\n";
}
}
?>
so I'm instantiating L, L is a subclass of P and C2 is a subclass of L.
The contructor for L creates an instance of C2.
I just want users to have to require_once the L class file (L.php) and
not have to think about P.php or C2.php so I include them in L.php
(incase it helps, in real life P is PEAR.php, L is LDAP.php, and C2 is
Connection.php)
When I run demo.php I get
'Fatal error: Class c2: Cannot inherit from undefined class l in C2.php
on line 2'
if I move the 'require_once "C.php";' line from L.php to demo.php I
don't get the error.
can anyone explain what is going on?
.~.
/v\ L I N U X
// \\ >Phear the Penguin<
/( )\
^`~'^
If it beeps, port Linux to it.
-Somebody.