I'ld like to dynamically create as many object as present in my $instance array (e.g. domain1_com and domain2_com) and give them the name of array value (e.g. domain1_com and domain2_com) so I can access it through these names (e.g. domain1_com->example()).
Is it possible? I tried something like this but obviously doesn't work.
class myClass
{
public static function getInstances()
{
// I connect to the database and execute the query
$sql = "SELECT * FROM my_table";
$core = Core::getInstance();
$stmt = $core->dbh->prepare($sql);
if ($stmt->execute()) {
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// Read values in my array
foreach ($results as $instance) {
$obj = $instance["domain"]);
// return 2 values: domain1_com and domain2_com
$obj = new myClass();
}
}
public function example()
{
echo "This is an instance";
}
}
myClass::getInstances();
$domain1_com->example();
$domain2_com->example();