|
Posted by Jerry Stuckle on 03/21/07 18:55
mountain.dog@gmail.com wrote:
> Hi There,
> I'm trying to understand inheriting properties object and I'm not
> fully understanding the ways to accomplish this.
>
> For example, I have a PHP array that is generate in "class a". I
> would like to use this array with its values in "class b". When I
> create a new instance of "class b" I get the array but none of the
> values are present. Make sense? An explanation on how to accomplish
> this would be great. A simplified example is below. Any help /
> guidance would be greatly welcome. -- CH
>
> class a {
> public $one;
>
> public function someMethod() {
> $one = array("1");
> }
> }
>
> class b extends class a {
> public $one;
> public $two
>
> function someOtherMethod() {
> print_r($this->one);
> }
> }
>
> $display = new a;
> $displayb = new b($a);
> $displayb->someOtherMethod();
>
> //outputs
> Array ( [0] => )
>
Two problems.
First of all, $one in class 'b' overrides $one in class 'a'. So you end
up with two variables named $one - one in 'a' and one in 'b'.
Secondly, you don't need
$display = new a;
When you create an instance if 'b' you automatically get an instance of
'a'. 'a' is part of 'b's implementation.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|