Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 0.32 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Disallow variable overwrite in PHP
  2. class Test
  3. {
  4.     private $variable;
  5.     private $frozen = false;
  6.  
  7.     public function freeze() {
  8.         $this->frozen = true;
  9.     }
  10.  
  11.     public function setVariable($value) {
  12.         if ($this->frozen)
  13.             throw new Exception("...");
  14.  
  15.         $this->variable = $value;
  16.     }
  17. }