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 ?
class definition with other classes and arrays
Moderator: General Moderators
once again
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 ?
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 ?
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
Code: Select all
class E {
private $class_a;
public function setClassA ( A $class_a ) { // type hinting
$this->class_a = $class_a;
}
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you can actually use instanceof or is_a()