Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Dependency Injection PHP

class Author {
    private $firstName;
    private $lastName;
     
    public function __construct($firstName, $lastName) {
        $this->firstName = $firstName;
        $this->lastName = $lastName;
    }
 
    public function getFirstName() {
        return $this->firstName;
    }
 
    public function getLastName() {
        return $this->lastName;
    }
}
 
class Question {
    private $author;
    private $question;
 
    public function __construct($question, Author $author) {
        $this->author = $author;
        $this->question = $question;
    }
 
    public function getAuthor() {
        return $this->author;
    }
 
    public function getQuestion() {
        return $this->question;
    }
}
Source by code.tutsplus.com #
 
PREVIOUS NEXT
Tagged: #Dependency #Injection #PHP
ADD COMMENT
Topic
Name
1+7 =