Answer the question
In order to leave comments, you need to log in
OOP why return the value of a non-inherited class?
class Member {
private $username;
public function __construct( $username ) {
$this->username = $username;
}
public function getUsername() {
return $this->username;
}
}
class Topic {
private $member;
private $subject;
public function __construct( $member, $subject ) {
$this->member = $member;
$this->subject = $subject;
}
public function getUsername() {
return $this->member->getUsername();
}
}
$aMember = new Member( "fred" );
$aTopic = new Topic( $aMember, "Hello everybody!" );
echo $aTopic->getUsername(); // Displays "fred"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question