class extends - need explanation to php class and declaration order behaviour

[email protected] ("Sek-Mun Wong") Wed, 6 Aug 2003 19:02:32 +1000
Newsgroups php.lang
Organization Connecting Space
Message-ID <[email protected]>
I know the manual says that classes must be declared before being invoked,
but this works

--- snippet 1 start ---
$obj = new Class1();

class Class1
{
    Class1() {
    }
}
--- snippet 1 end ---


Now, say I do this:

--- snippet 2 start ---
require_once("class2.php"); // say, this is class 2, which looks like
snippet 1

$obj = new Class1();

class Class1 extends Class2
{
    Class1() {
    }
}
--- snippet 2 end ---

this just dies, but

--- snippet 3 start ---
require_once("class2.php"); // say, this is class 2, which looks like
snippet 1

class Class1 extends Class2
{
    Class1() {
    }
}

$obj = new Class1();
--- snippet 3 end ---

this works (note the order of declaration)

Now, I guess I could write code like snippet 3, or even do:

--- snippet 4 start ---
require_once("class1.php"); // just being retentive
require_once("class2.php"); // and again
$obj = new Class1();
--- snippet 4 end ---

and that would work, but can someone explain this behaviour to me?

I thought php pre-parsed and pre-compiled before it begins going through the
code?

And why would it work in a simple case, but not with extends?

thanks