I didn't see where this issue was addressed so in regards to this post:
\\-------\\//-------//
when using "::" operator inside class functions, you can achieve quite interesting results. let's take this example:
class cCat {
function Miew(){
// cCat does not have a member "kind", but cDog has, and we'll use it
echo "I am ".$this->kind.", and I say MIEW\n";
// here things are even stranger: does cCat class
// support WhoAmI function? guess again...
$this->WhoAmI();
}
}
class cDog {
var $kind = "DOG";
function Bark(){
// let's make this dog act like a cat:)
cCat::Miew();
}
function WhoAmI(){
echo "Yes, I'm really ".$this->kind."!";
}
}
$dog = new cDog();
echo $dog->Bark();
outputs:
I am DOG, and I say MIEW
Yes, I'm really DOG!
The interesting thing here is that cDog is not descendant of cCat nor vice versa, but cCat was able to use cDog member variable and function. When calling cCat::Miew() function, your $this variable is passed to that function, remaining cDog instance!
It looks like PHP doesn't check if some class is an ancestor of the class, calling function via '::'.
//------//\\--------\\
The problem here is not that PHP is not checking ancestry. The problem is that "$this" refers to the calling object $dog even though it is referenced inside the cCat class definition. Since a cCat is never instantiated, $this has not been scoped to it.
To further illustrate the point, if you never instatiate dog (or any object for that matter), $this will never be set and when you statically call the miew function, you will get the following output:
"I am , and I say MIEW"
This flexibility of member handling, PHP does not afford to methods and as such the second line of the miew function will generate a fatal error reporting that the method has been called from a non object.
If you did want to take it one step further in the whole ancestry guessing issue, try instatiating cCat and calling the miew function. You will get the same result as above *EXCEPT* the fatal error will inform you the function has not been defined.
So, there you have it--PHP DOES NOT guess at inheritance.