[Phplib-commit] CVS: php-lib/php/ext template.inc,1.8,1.9
Brought to you by:
nhruby,
richardarcher
From: Richard A. <ric...@us...> - 2002-07-11 22:20:32
|
Update of /cvsroot/phplib/php-lib/php/ext In directory usw-pr-cvs1:/tmp/cvs-serv11136 Modified Files: template.inc Log Message: Added clear_var to set the value of variables to "". Added unset_var to usset variables. Index: template.inc =================================================================== RCS file: /cvsroot/phplib/php-lib/php/ext/template.inc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** template.inc 25 Apr 2002 12:53:38 -0000 1.8 --- template.inc 11 Jul 2002 22:20:28 -0000 1.9 *************** *** 33,37 **** * more elegant fix to the problem of subst stripping '$n', '\n' and '\\' strings (rha) * - * * changed debug handling so set, get and internals can be tracked separately (rha) * added debug statements throughout to track most function calls (rha) --- 33,36 ---- *************** *** 41,44 **** --- 40,45 ---- * Altered parse so that append is honored if passed an array (Brian) * Converted comments and documentation to phpdoc style. (rha) + * Added clear_var to set the value of variables to "". (rha) + * Added unset_var to usset variables. (rha) * */ *************** *** 371,374 **** --- 372,459 ---- $this->varvals[$k] = $v; } + } + } + } + } + + + /****************************************************************************** + * This functions clears the value of a variable. + * + * It may be called with either a varname as a string or an array with the + * values being the varnames to be cleared. + * + * The function sets the value of the variable in the $varkeys and $varvals + * hashes to "". It is not necessary for a variable to exist in these hashes + * before calling this function. + * + * + * usage: clear_var(string $varname) + * or + * usage: clear_var(array $varname = (string $varname)) + * + * @param $varname either a string containing a varname or an array of varnames. + * @access public + * @return void + */ + function clear_var($varname) { + if (!is_array($varname)) { + if (!empty($varname)) { + if ($this->debug & 1) { + printf("<b>clear_var:</b> (with scalar) <b>%s</b><br>\n", $varname); + } + $this->set_var($varname, ""); + } + } else { + reset($varname); + while(list($k, $v) = each($varname)) { + if (!empty($v)) { + if ($this->debug & 1) { + printf("<b>clear_var:</b> (with array) <b>%s</b><br>\n", $v); + } + $this->set_var($v, ""); + } + } + } + } + + + /****************************************************************************** + * This functions unsets a variable completely. + * + * It may be called with either a varname as a string or an array with the + * values being the varnames to be cleared. + * + * The function removes the variable from the $varkeys and $varvals hashes. + * It is not necessary for a variable to exist in these hashes before calling + * this function. + * + * + * usage: unset_var(string $varname) + * or + * usage: unset_var(array $varname = (string $varname)) + * + * @param $varname either a string containing a varname or an array of varnames. + * @access public + * @return void + */ + function unset_var($varname) { + if (!is_array($varname)) { + if (!empty($varname)) { + if ($this->debug & 1) { + printf("<b>unset_var:</b> (with scalar) <b>%s</b><br>\n", $varname); + } + unset($this->varkeys[$varname]); + unset($this->varvals[$varname]); + } + } else { + reset($varname); + while(list($k, $v) = each($varname)) { + if (!empty($v)) { + if ($this->debug & 1) { + printf("<b>unset_var:</b> (with array) <b>%s</b><br>\n", $v); + } + unset($this->varkeys[$v]); + unset($this->varvals[$v]); } } |