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

From: Date: Wed, 06 Aug 2003 09:02:32 +0000
Subject: class extends - need explanation to php class and declaration order behaviour
Groups: php.lang 
Request: Send a blank email to php-lang+get-521@lists.php.net to get a copy of this message
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

« previous php.lang (#521) next »