I want to add a dog object to an array and var_dump
it after but the array stays empty. Am I breaking some rule of the OOP concept or something?
class Dog {
public $name;
public $bread;
}
class MyClass {
public $dogArr = [];
public function __construct( $key , callable $callback ) {
$dogArr[$key] = $callback ();
}
}
public function actionTest() {
$newDog = new \backend\components\MyClass ( "first" , function () {
$dog = new \backend\components\Dog();
$dog->name = "Archi";
$dog->bread = "Pomeran";
return $dog;
} );
var_dump ( $newDog->dogArr );
}