Welcome

Welcome to the Forums, Blogs, Wikis discussion boards. If you're new here please take a moment to register for an account. If you're already a member here, welcome back. Please login to join in.

Forums, Blogs, Wikis » Coding

Clear all PHP class variables

  • Started 2 years ago by ryan

Tags:

  1. The more I'm using data classes in PHP the more I find myself writing _clear() functions to empty out the variables. I finally did some searching and found a starting point for a function that would do it for me without having to hard code in each of the variable names. I don't remember where this starting point came from, but it didn't work out of the box anyway.

    function _clear()
    {
    $arr = get_object_vars($this);
    foreach ($arr as $key => $value)
    {
    unset($this->$key);
    }
    }

    Ryan
    Posted 2 years ago #

RSS feed for this topic

Reply

You must log in to post.