How to destroy an object?

后端 未结 6 1112
挽巷
挽巷 2020-11-29 01:54

As far as I know (which is very little) , there are two ways, given:

$var = new object()

Then:

// Method 1: Set to null
$va         


        
6条回答
  •  野性不改
    2020-11-29 02:43

    A handy post explaining several mis-understandings about this:

    Don't Call The Destructor explicitly

    This covers several misconceptions about how the destructor works. Calling it explicitly will not actually destroy your variable, according to the PHP5 doc:

    PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as there are no other references to a particular object, or in any order during the shutdown sequence.

    The post above does state that setting the variable to null can work in some cases, as long as nothing else is pointing to the allocated memory.

提交回复
热议问题