class definition with other classes and arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mihalka
Forum Newbie
Posts: 10
Joined: Thu Oct 13, 2005 2:19 pm

class definition with other classes and arrays

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

8O8O you've made so little sense in that post..
mihalka
Forum Newbie
Posts: 10
Joined: Thu Oct 13, 2005 2:19 pm

once again

Post 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 ?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can actually use instanceof or is_a()
Post Reply