Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Analogue Of ColdFusion's CFPARAM Tag In PHP.

DZone's Guide to

An Analogue Of ColdFusion's CFPARAM Tag In PHP.

·
Free Resource

/**
 * Checks if $var is already defined and if not, sets it to
 * $default.
 *
 * @param  $var         Variable to check.
 * @param  $default     Value to give the checked variable if
 *                      found to be null; "" by default.
 * @param  $catchNulls  TRUE: treat empty strings as null; FALSE
 *                      by default.
 *
 * @note   It's a lot like ColdFusion's 
  
    tag.
 */
function set_default(&$var, $default="", $catchNulls=FALSE) {
    if (!isset($var) || ($catchNulls && $var == "")) {
        $var = $default;
    }
}

  
This appears to have stopped working as of PHP 5.
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}