Skip to content

Instantly share code, notes, and snippets.

@klhall1987
Last active December 30, 2015 20:58
Show Gist options
  • Save klhall1987/db8b68457587ef779eca to your computer and use it in GitHub Desktop.
Save klhall1987/db8b68457587ef779eca to your computer and use it in GitHub Desktop.
<?php
class phone
{
/**
* @var string
*/
private $brand = '';
/**
* @var string
*/
private $model = '';
/**
* phone constructor.
* @param $brand
* @param $model
*
* Here we are creating the phone constructor and setting the params that the phone class will pass to
* the user class.
*/
public function __construct( $brand, $model )
{
$this->brand = $brand;
$this->model = $model;
}
/**
* @return string
*/
public function getBrand()
{
return $this->brand;
}
/**
* @return string
*/
public function getModel()
{
return $this->model;
}
}
class user
{
/**
* @var
*/
private $userPhone;
/**
* @var string
*/
private $userName = '';
/**
* user constructor.
* @param $userName
* @param $phoneBrand
* @param $phoneModel
*
* In the user constructor we are creating a new instance of the phone object, setting the instance to the
* userPhone variable, and passing the params into the constructor.
*/
public function __construct( $userName, $phoneBrand, $phoneModel )
{
$this->userName = $userName;
//setting userPhone to new instance of phone and passing in the params needed to create the object.
$this->userPhone = new phone( $phoneBrand, $phoneModel );
}
public function getUserName()
{
return $this->userName;
}
public function getUserPhone()
{
return $this->userPhone;
}
}
$user = new user( 'Kenny', 'HTC', 'One M8' );
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