Home >Backend Development >PHP Tutorial >PHP structure and destruction

PHP structure and destruction

WBOY
WBOYOriginal
2016-07-29 09:02:50866browse

When instantiating a new object, the constructor and destructor methods will be automatically called. If there is inheritance, the corresponding method of the parent class will be used.

  • The destructor method will be called in three situations:

    • Use unset() to destroy an object. If there is an object passed by value, it will not be called;
    • Change the value of the variable pointing to the object;
    • After the php program code has finished running.
<code><span><span><?php </span><span><span>class</span><span>base</span>{</span><span>public</span><span>$name</span>;

    <span><span>function</span><span>__construct</span><span>(<span>$name</span>)</span>{</span><span>$this</span>->name = <span>$name</span>;
        <span>echo</span><span>'obj '</span>.<span>$this</span>->name.<span>' have built'</span>.<span>''</span>.<span>''</span>;
    }
    <span><span>function</span><span>__destruct</span><span>()</span>{</span><span>echo</span><span>'obj '</span>.<span>$this</span>->name.<span>' have destroyed'</span>.<span>''</span>.<span>''</span>;
    }
}

<span>$a</span> = <span>new</span> base(<span>'a'</span>);
<span>$b</span> = <span>new</span> base(<span>'b'</span>);
<span>$c</span> = <span>new</span> base(<span>'c'</span>);

<span>unset</span>(<span>$b</span>);
<span>$c</span> = <span>'d'</span>;</span></span></code>

PHP structure and destruction

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the structure and destruction of PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:nginx伪静态配置实例Next article:mac配置impala odbc