Question: Let's say I have these classes:

```
abstract class AbstractEntity {
    function __construct($args = array()) {
        foreach ($args as $property => $value) {
            $this->{$property} = $value;
        }
    }

    public function __get( $property ) {
        if( isset( $this->{$property} ) ) {
            return $this->{$property};
        } else {
           throw new \Exception( 'Porperty ' . $property . ' not found!' );
        }
    }
    public function __set($property, $value) {
        if( isset( $this->{$property} ) ) {
            $this->{$property} = $value;
        } else {
            throw new \Exception( 'Porperty ' . $property . ' not found!' );
        }
    }
}

class Person extends AbstractEntity {
    protected $name;
}

class Group extends AbstractEntity  {
    protected $people; // array of Person
}

```

Now I want to populate the `$people` property with `Person` objects in a loop, like:

```
$group = new Group( array( 'people' => array() ) );

foreach ( get_people_data() as $person_data ) {
    $group->people[] = new Person( $person_data['name'] );
}

```

But this doesn't work, I get an error:

```
Notice: Indirect modification of overloaded property Group::$people has no effect in ...

```

I know I can use a temp array, fill it with `Person` objects and then assign it to the `$people` property, but I kind of don't like it... so, is there any other solution?

Answer: 
Eventually I added a function to my `AbstractEntity` class that allows to add a `$value` to a `$property` of the class, which must be an `array`:

```
public function append_to( $property, $value ) {

    // Check that $property exists on the object and is an array
    if( isset( $this->{$property} ) && is_array( $this->{$property} ) ) {

        $this->{$property}[] = $value;

    } else {

        throw new \Exception( 'Porperty ' . $property . ' not found or is not array!' );
    }
}

```

These has some benefits (in my opinion) than other approaches commented here:

1. I don't need to make any field `public`.
2. I don't have to create a function like `addPerson()`, so I can keep all the classes extending `AbstractEntity` as a simple bunch of properties without ANY function.
Your code seems kind of incomplete and this is what my assumption and see how it goes...

```
<?php

class Person {
    public $name;
    function __construct($n)
    {
        $this->name=$n;
    }
}

class Group {
public $people = array(); // array of Person
}

$arr = [0=>['name'=>'John'],1=>['name'=>'Jack'],2=>['name'=>'Jill']];
$group = new Group();
foreach ($arr as $person_data ) {
    $group->people[] = new Person( $person_data['name'] );
}
print_r($group->people);

```

**`OUTPUT :`**

```
Array
(
    [0] => Person Object
        (
            [name] => John
        )

    [1] => Person Object
        (
            [name] => Jack
        )

    [2] => Person Object
        (
            [name] => Jill
        )

)

```