STATIC Newbness

I am sure some of you old time programmers were quite aware of the STATIC keyword. I however, have recently discovered it. I had used it sporadically in C and other languages but never in PHP. STATIC basically maintains the value of a variable within that function no matter how many times it is called from the script.

function form_error()
{
    STATIC $error = 0;
    $error++;

    return $error;
}

Yeah, it is nothing revolutionary. It is definitely something new to work with. Rather than creating a mess of global variables and having to pass them or declare them within various places I can call this function and then when I need to check if there are any errors, I can do so simply by checking to see if the function is returning more than 0.

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.