1. __toString()
2. __invoke()
3. call(), callStatic() — 메서드 오버로드(덮어쓰기)
4. __get(), __set() —속성 오버로딩(오버로딩)
5. __clone()
<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>
이상은 관련 내용을 포함하여 47가지 PHP 매직 메소드를 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.