Does my “use CodeIgniter functions in CamelCase” hack qualify?
Also could you add rule #4: put the code between [code ][/code ] tags
And just in case that other bit of crazyness didn’t qualify:
[code]function is_true( $var )
{
// Set the default value for the return just in case
// according to the rule: innocent until proven guilty
$return = TRUE;
// If the input is boolean the truth can be decided immediately
if ( is_bool( $var ) )
{
if ( $var === TRUE )
{
$return = TRUE;
}
elseif ( $var === FALSE )
{
$return = FALSE;
}
// Throw error when $var has an invalid value
else
{
throw new Exception( 'Boolean value has to be TRUE or FALSE.' );
}
}
// If the input isn’t boolean the $var has to be converted to boolean before truth
// can be determined
else
{
if ( is_null( $var ) )
{
$return = FALSE;
}
elseif ( is_numeric( $var ) )
{
if ( $var > 0 )
$return = TRUE;
else
$return = FALSE;
}
elseif ( is_string( $var ) )
{
if ( strlen( $var ) > 0 )
$return = TRUE;
else
$return = FALSE;
}
elseif ( is_array( $var ) )
{
if ( count( $var ) > 0 )
$return = TRUE;
else
$return = FALSE;
}
elseif ( is_object( $var ) )
{
if ( ! is_null( $var ) )
$return = TRUE;
else
$return = FALSE;
}
// If type wasn’t determined yet use empty()
else
{
if ( ! empty( $var ) )
$return = TRUE;
else
$return = FALSE;
}
}
// Return the truth of the matter
return $return;
}</code></pre>