Skip to content

Instantly share code, notes, and snippets.

@colindecarlo
Created March 26, 2012 18:45
Show Gist options
  • Save colindecarlo/2208624 to your computer and use it in GitHub Desktop.
Save colindecarlo/2208624 to your computer and use it in GitHub Desktop.
A class method that is both a getter and a setter
<?php
class ACDC {
protected $_data = null;
public function data()
{
$args = func_get_args();
if (!empty($args)) {
$this->_data = array_shift($args);
}
return $this->_data;
}
}
$acdc = new ACDC();
$acdc->data('Hello World');
echo $acdc->data();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment