Page 1 of 1
class definition with other classes and arrays
Posted: Fri Nov 04, 2005 4:35 pm
by mihalka
There is classses A, B, C, D and E
The class E should have a properties and functions as follwed:
$iAmACassOfTypA
$iAmAnArrayOfTypB
function iGetAClassCAndIReturnAnArrayOfClassD()
How to do it ?
Posted: Fri Nov 04, 2005 4:44 pm
by feyd
8O8O you've made so little sense in that post..
once again
Posted: Fri Nov 04, 2005 5:01 pm
by mihalka
class A {}
class B {}
class C {}
class D {}
class E {
$iAmACassOfTypA; // this variable have to be a typ of class A - how to declare / restrict it ?
$iAmAnArrayOfTypB // this variable have to be a typ of array of class B - how to declare / restrict it ?
function iGetAClassCAndIReturnAnArrayOfClassD($imAClassOfC) {return $this->iAmAnArrayOfTypB}
// how to declare the argument $imAClassOfC as Class C ?
Posted: Fri Nov 04, 2005 5:19 pm
by andre_c
Code: Select all
class E {
private $class_a;
public function setClassA ( A $class_a ) { // type hinting
$this->class_a = $class_a;
}
}
since php is loosely typed, there isn't much more you can do to restrict it besides
type-hinting
Posted: Fri Nov 04, 2005 6:17 pm
by feyd
you can actually use
instanceof or
is_a()