首頁 >後端開發 >php教程 >47 PHP 魔術方法

47 PHP 魔術方法

WBOY
WBOY原創
2016-07-29 09:13:31782瀏覽

1. __toString()
47 <strong>PHP 魔術方法</strong>

2. __invoke()
47 <strong>PHP 魔術方法</strong>">

PHP 魔術方法
" title="">方法重載(overwrite)47 <strong></strong>PHP 魔術方法</p>

47 <strong></strong>PHP 魔術方法</p>


4. __get(),__set() —屬性重載( 47 <strong>PHP 魔術方法</strong>

5. __clone()

47 <strong>PHP 魔術方法</strong>

<code><span><span>class</span><span>A</span>
{</span><span>public</span><span>$name</span>;
}

<span>$aa</span> = <span>new</span> A();
<span>$aa</span>->name = <span>'wjh'</span> . <span>'<br/>'</span>;
<span>echo</span><span>$aa</span>->name;

<span>$bb</span> = <span>clone</span><span>$aa</span>;
<span>$bb</span>->name = <span>'wang lu xi'</span>;  <span>//不改变赋值对象的属性</span><span>echo</span><span>$bb</span>->name . <span>'<br/>'</span>;
<span>echo</span><span>$aa</span>->name . <span>'<br/>'</span>;</code>
<code><span><span><?php</span><span><span>class</span><span>A</span>
{</span><span>public</span><span>$name</span>;

    <span>public</span><span><span>function</span><span>__clone</span><span>()</span>  // 魔术方法,只要<span>clone</span>就运行这个方法
    {</span><span>$this</span>->name = <span>' wei jian hua'</span>;
    }
}

<span>$aa</span> = <span>new</span> A();
<span>$aa</span>->name = <span>'wjh'</span> . <span>'<br/>'</span>;
<span>echo</span><span>$aa</span>->name;

<span>$bb</span> = <span>clone</span><span>$aa</span>;

<span>echo</span><span>$bb</span>->name;</span></span></code>
').addClass('prenumbering'">​​rrreeerrreee').addClass('prenumbering'). $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i

').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了47 PHP 魔術方法,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。

🎜 🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn