Capsule::clear PHP Method

clear() public method

Clears one or several or all variables.
public clear ( mixed $which = null ) : void
$which mixed String name of var, or array of names.
return void
    function clear($which = null)
    {
        if ($which === null) {
            $this->vars = array();
        } elseif (is_array($which)) {
            foreach ($which as $var) {
                unset($this->vars[$var]);
            }
        } else {
            unset($this->vars[$which]);
        }
    }

Usage Example

Example #1
0
 /**
  * Creates a Smarty object.
  *
  * @return Capsule   initialized (cleared) Smarty context.
  * @throws Exception the execute method will catch
  *                   and rethrow as a <code>BuildException</code>
  */
 public function initControlContext()
 {
     $this->context->clear();
     foreach ($this->assignedVars as $var) {
         $this->context->put($var->getName(), $var->getValue());
     }
     return $this->context;
 }