Last active
December 30, 2015 20:41
-
-
Save klhall1987/65d8edb5e6b6430b0ee6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class user | |
{ | |
/** | |
* @var | |
*/ | |
private $userPhone; | |
/** | |
* @var string | |
*/ | |
private $userName = ''; | |
/** | |
* user constructor. | |
* @param $userName | |
* @param phone $userPhone | |
* | |
* Using the same phone object from the previous example we have injected an instance of the phone object | |
* into the constructor. Now when we instantiate this object later we will need to pass in an instance of the phone | |
* object. This means we no longer need to hard code the params from the phone object into this constructor. | |
*/ | |
public function __construct( $userName, phone $userPhone ) | |
{ | |
$this->userName = $userName; | |
$this->userPhone = $userPhone; | |
} | |
public function getUserName() | |
{ | |
return $this->userName; | |
} | |
public function getUserPhone() | |
{ | |
return $this->userPhone; | |
} | |
} | |
$phone = new phone( 'HTC', 'One M8' ); | |
$user = new user( 'Kenny', $phone ); | |
echo '<pre>' . '<br>'; | |
print_r( $user ); | |
echo '<pre>'; | |
****************************OUTPUT********************************** | |
user Object | |
( | |
[userPhone:user:private] => phone Object | |
( | |
[brand:phone:private] => HTC | |
[model:phone:private] => One M8 | |
) | |
[userName:user:private] => Kenny | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment