I have this problem:
<?php
class A {
}
class B {
}
$objectsInArray = array();
$objectsInArray[] = new A();
$objectsInArray[] = new B();
class C {
private $a;
private $b;
public function __construct(A $a, B $b) {
$this->a = $a;
$this->b = $b;
}
}
How can I pass $objectInArray to class C() directly like this:
$c = new C($objectsInArray);
without this error message:
Catchable fatal error: Argument 1 passed to C::__construct() must be an instance of A, array given...
and i don't want this reason:
class C {
private $a;
private $b;
public function __construct(array $arguments) {
foreach ($arguments as $argument) {
if ($argument instanceof A) {
$this->a = $argument;
} elseif ($argument instanceof B) {
$this->b = $argument;
} else {
throw new exception('Arguments are bad!');
}
}
}
}
Thanks for answers.