Jump to content

[SOLVED] Merging Properties


slogger2

Recommended Posts

Is it possible to merge a property in a child object with a property in its parent object? I will give an example to describe:

 

class A {

  var $something;

  function show() {

    foreach($this->stuff as $thing) {

      echo $thing . " ";

    }

  }

}


class B extends A {

  var $something = array(1,2,3);

}

class C extends B {

  var $something = array(4,5,6);

}

$myVar = new C();

$myVar->show(); // Desired output: 1 2 3 4 5 6

 

Essentially, when I set the value of a property in a child class, I want it to be merged with the same property in its parent class. I'm not sure if this is possible, but I think it would be because in CakePHP, some properties (such as the $uses variable in a controller) is merged with that of its parent (namely AppController). I would presume that this requires either some control functionality in either the base class (in this case, class A), or the code which runs the class.

 

Thanks a bundle in advance...

Link to comment
https://forums.phpfreaks.com/topic/143376-solved-merging-properties/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.