Skip to content

Instantly share code, notes, and snippets.

@zacharydanger
Created August 31, 2009 16:41
Show Gist options
  • Save zacharydanger/178556 to your computer and use it in GitHub Desktop.
Save zacharydanger/178556 to your computer and use it in GitHub Desktop.
<?php
class Foobar {
static $global_value;
private $_local_value;
public function __construct($local_val = null) {
if(false == is_null($local_val)) {
$this->_local_value = $local_val;
}
}
public function getValue() {
return isset($this->_local_value) ? $this->_local_value : Foobar::$global_value;
}
}
Foobar::$global_value = 'global_value';
echo Foobar::$global_value . "\n"; //global_value
$F = new Foobar();
echo $F->getValue() . "\n"; //global_value
$F = new Foobar('new value');
echo $F->getvalue() . "\n"; //new value
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment