Home >Backend Development >PHP Tutorial >PHP structure and destruction
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:
<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>').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.