47 PHP 魔术方法

WBOY
Lepaskan: 2016-07-29 09:13:31
asal
774 orang telah melayarinya

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

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

3. call(),callStatic() —方法重载(overwrite)
47 <strong>PHP 魔术方法</strong>

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

4. __get(),__set() —属性重载(overloading)
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>
Salin selepas log masuk
<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>
Salin selepas log masuk
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了47 PHP 魔术方法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan