Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Name{
- protected $first ;
- public function setNameType($value) {
- $this->first = $value;
- }
- public function getNameType() {
- return $this->first;
- }
- }
- $name = new Name;
- $name->setNameType("My Name");
- echo $name->getNameType();
- ?>
- <?php
- class Name{
- protected $first ;
- public function __construct($value) {
- $this->first = $value;
- }
- public function getNameType() {
- return $this->first;
- }
- }
- $name = new Name("My Name");
- echo $name->getNameType();
- ?>
- class Book {
- public function __construct() {
- $registry = RegistrySingleton::getInstance();
- $this->_database = $registry->database;
- // or
- global $databaseConnection;
- $this->_database = $database;
- }
- }
- class Book {
- private $_databaseConnection;
- public function __construct() { }
- public function setDatabaseConnection($databaseConnection) {
- $this->_databaseConnection = $databaseConnection;
- }
- }
- $book = new Book();
- $book->setDatabase($databaseConnection);
- $book = new Book($databaseConnection, $configFile);
- $book = new Book();
- $book->setDatabase($databaseConnection);
- $book->setConfigFile($configFile);
- class Container {
- public static $_database;
- public static function makeBook() {
- $book = new Book();
- $book->setDatabase(self::$_database);
- // more injection...
- return $book;
- }
- }
- $book = Container::makeBook();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement