PHP OOP: Parenting objects/functions?
Posted
by Industrial
on Stack Overflow
See other posts from Stack Overflow
or by Industrial
Published on 2010-05-28T15:37:59Z
Indexed on
2010/05/28
15:51 UTC
Read the original article
Hit count: 181
Hi everyone,
How is parenting functions in PHP done properly according to the following example? Can I make sure that my array isn't overwritten and the previous values inside array lost, on each addArray call?
function arraybase() {
$this->array = new ArrayObject();
return $this;
}
function addArray($value) {
parent::$this->arraybase();
$this->array->append($value);
return $this;
}
$this->addArray('1')->addArray('2')->addArray('3');
// outputs:
Array
(
[0] => 3
)
Thanks a lot!
© Stack Overflow or respective owner