Created
February 6, 2012 15:28
-
-
Save casparjones/1752667 to your computer and use it in GitHub Desktop.
points
This file contains 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 | |
ini_set('display_errors', 1); | |
error_reporting (E_ALL); | |
class MyObject { | |
public $points; | |
protected $_points; | |
public function __construct() { | |
$this->points = new Points($this); | |
} | |
public function getPoints() { | |
return $this->_points; | |
} | |
public function setPoint($iPoints) { | |
$this->_points = $iPoints; | |
} | |
} | |
class Points { | |
const LIKE = 10; | |
const LOVE = 100; | |
protected $refObject; | |
public function __construct($refObject) { | |
$this->refObject = $refObject; | |
} | |
public function add($iValue) { | |
$this->refObject->setPoint($this->refObject->getPoints() + $iValue); | |
} | |
} | |
$myObject = new MyObject(); | |
$myObject->points->add(Points::LIKE); | |
var_dump($myObject); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment