Home  |  Linux  | Mysql  | PHP  | XML
From:Sek-Mun Wong Date:Wed Aug  6 03:02:32 2003
Subject:class extends - need explanation to php class and declaration order behaviour
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

Navigate in group php.lang at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by Zareef Ahmed
Powered By PHP Consultants