Skip to content

Instantly share code, notes, and snippets.

@casparjones
Created February 6, 2012 15:28
Show Gist options
  • Save casparjones/1752667 to your computer and use it in GitHub Desktop.
Save casparjones/1752667 to your computer and use it in GitHub Desktop.
points
<?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