From ceef12645c9254f50ffbeb6d23a2539dc9299e7a Mon Sep 17 00:00:00 2001 From: secretr Date: Fri, 28 Aug 2009 00:22:08 +0000 Subject: [PATCH] added vartrue(), alias of varsettrue(); added deftrue(), alias of defsettrue() --- e107_handlers/core_functions.php | 85 ++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 16 deletions(-) diff --git a/e107_handlers/core_functions.php b/e107_handlers/core_functions.php index 3e762b43b..c034bd39f 100644 --- a/e107_handlers/core_functions.php +++ b/e107_handlers/core_functions.php @@ -9,46 +9,99 @@ * e107 Core functions * * $Source: /cvs_backup/e107_0.8/e107_handlers/core_functions.php,v $ - * $Revision: 1.1 $ - * $Date: 2009-08-05 19:53:47 $ + * $Revision: 1.2 $ + * $Date: 2009-08-28 00:22:08 $ * $Author: secretr $ */ // -// Use these to combine isset() and use of the set value. or defined and use of a constant -// i.e. to fix if($pref['foo']) ==> if ( varset($pref['foo']) ) will use the pref, or ''. -// Can set 2nd param to any other default value you like (e.g. false, 0, or whatever) -// $testvalue adds additional test of the value (not just isset()) -// Examples: -// $something = pref; // Bug if pref not set ==> $something = varset(pref); -// $something = isset(pref) ? pref : ""; ==> $something = varset(pref); -// $something = isset(pref) ? pref : default; ==> $something = varset(pref,default); -// $something = isset(pref) && pref ? pref : default; ==> use varsettrue(pref,default) + // + +/** + * Use these to combine isset() and use of the set value. or defined and use of a constant + * i.e. to fix if($pref['foo']) ==> if ( varset($pref['foo']) ) will use the pref, or ''. + * Can set 2nd param to any other default value you like (e.g. false, 0, or whatever) + * $testvalue adds additional test of the value (not just isset()) + * Examples: + * + * $something = pref; Bug if pref not set ==> $something = varset(pref); + * $something = isset(pref) ? pref : ""; ==> $something = varset(pref); + * $something = isset(pref) ? pref : default; ==> $something = varset(pref,default); + * $something = isset(pref) && pref ? pref : default; ==> use varsettrue(pref,default) + * + * + * @param mixed $val + * @param mixed $default [optional] + * @return mixed + */ function varset(&$val, $default='') { if (isset($val)) { return $val; } return $default; } +/** + * Check if the given string is defined (constant) + * + * @param string $str + * @param mixed $default [optional] + * @return + */ function defset($str, $default='') { if (defined($str)) { return constant($str); } return $default; } -// -// These variants are like the above, but only return the value if both set AND 'true' -// +/** + * Variant of {@link varset()}, but only return the value if both set AND 'true' + * + * @param mixed $val + * @param mixed $default [optional] + * @return mixed + */ function varsettrue(&$val, $default='') { if (isset($val) && $val) { return $val; } return $default; } -function defsettrue($str,$default='') +/** + * Alias of {@link varsettrue()} + * + * @param mixed $val + * @param mixed $default [optional] + * @return mixed + */ +function vartrue(&$val, $default='') { - if (defined($str) && constant($str)) {return constant($str); } + return varsettrue($val, $default); +} + +/** + * Variant of {@link defset()}, but only return the value if both defined AND 'true' + * + * @param string $str + * @param mixed $default [optional] + * @return mixed + */ +function defsettrue($str, $default='') +{ + if (defined($str) && constant($str)) { return constant($str); } + return $default; +} + +/** + * Alias of {@link defsettrue()} + * + * @param string $str + * @param mixed $default [optional] + * @return mixed + */ +function deftrue($str, $default='') +{ + if (defined($str) && constant($str)) { return constant($str); } return $default; }