[UPHPU] Accessing a Parent Object's Other Variables

Kirk Cerny kirksemail at gmail.com
Tue Jun 23 13:13:49 MDT 2009


I would still not write it this way, but good point Alvaro.

Kirk Cerny

On Tue, Jun 23, 2009 at 11:44 AM, Alvaro Carrasco<alvaro at epliant.com> wrote:
> I disagree. Having a child hold a reference to it's parent (in composition
> of course) is a very common approach in object-oriented programming. I don't
> think you have any problem with readability by doing that and I don't think
> there's anything wrong with it at all.
>
> Alvaro
>
> Kirk Cerny wrote:
>>
>> But in this case it appears that A has B and B has A.
>> I would be alright if it was just A has B.
>> The circular part is where I think you get into trouble especially
>> with readability, and understandable code.
>>
>> Kirk Cerny
>>
>>
>>
>> On Mon, Jun 22, 2009 at 11:09 PM, Richard K
>> Miller<richardkmiller at gmail.com> wrote:
>>
>>>
>>> This is the composition vs. inheritance debate, right?
>>>
>>> In inheritance, B is a descendant of A. With composition, A has a B.
>>>
>>> Richard
>>>
>>>
>>>
>>> On Jun 22, 2009, at 9:07 PM, Kirk Cerny wrote:
>>>
>>>
>>>
>>>>
>>>> This just seems like a really bad idea to me.
>>>> You also mentioned that there is a parent class, but I dont see the
>>>> extends keyword.
>>>>
>>>> <?php
>>>>
>>>> Class A {
>>>>
>>>>  var $msg = 'Why hello there my old friend';
>>>>
>>>>  function  __construct() {
>>>>  }
>>>>
>>>> }
>>>>
>>>>
>>>> Class B extends A {
>>>>
>>>>  function __construct() {
>>>>  }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> $b = new B();
>>>>
>>>> echo $b->msg;
>>>>
>>>> Kirk Cerny
>>>>
>>>>
>>>>
>
>



More information about the UPHPU mailing list