I don't think it is even possible to access the "parent"'s version of $iId
: you don't actually re-define it in the child class : you only chance the value that was defined in the parent's class.
To makes things very simple : when you declare the Form_2
class that extends Form_1
, it takes all the properties and methods of Form_2
, and put them in Form_1
, overriding what was already existing there.
There is no longer "two distinct classes" : there is only one resulting object, that's both Form_1
and Form_2
at the same time.
And here's an example that kind of -- I hope -- will help understand what I mean :
class Form_Abstract {}
class Form_1 extends Form_Abstract {
public $iId = 1;
public function methodInParent() {
var_dump($this);
}
}
class Form_2 extends Form_1 {
public $iId = 2;
public function tryingToGetParentProperty() {
var_dump(parent::$iId);
}
}
$form2 = new Form_2();
$form2->methodInParent();
$form2->tryingToGetParentProperty();
Using this portion of code, the call to $form2->methodInParent()
will get you :
object(Form_2)#1 (1) {
["iId"]=>
int(2)
}
i.e. even if calling/executing a method that's defined in the parent's class, the $iId
property is still the value defined in the child class : there is one, and only one, version of that property !
And the call to $form2->tryingToGetParentProperty()
will get you :
Fatal error: Access to undeclared static property: Form_1::$iId
As there is no static
property called $iId
in Form_1
.
I suppose a solution to avoid that situation would be to declare $iId
as static
-- but note that it would change the meaning of your code, and the way it behaves !
i.e. the static
variable will be shared accross all instances of the class -- which is probably not what you want ^^