オブジェクトの下方受け渡し機能
オブジェクトがインスタンスメソッドを呼び出し、そのメソッド内で別のクラスのメソッドを静的に呼び出すと、ソースメソッド内のオブジェクト(this)
<code><span><span><?php </span><span><span>class</span><span>bee</span>{</span><span>public</span><span>$a</span> = <span>1</span>; <span>public</span><span><span>function</span><span>f</span><span>()</span>{</span><span>echo</span><span>$this</span>->a; <span>echo</span><span>'<br>'</span>; @lig::f(); } } <span><span>class</span><span>lig</span>{</span><span>public</span><span>$a</span> = <span>2</span>; <span>public</span><span><span>function</span><span>f</span><span>()</span>{</span><span>echo</span><span>$this</span>->a; } } <span>$obj</span> = <span>new</span> bee(); <span>$obj</span>->f();</span></span></code>
static late static binding
staticには3つの異なる構文の意味があります
<code><span><span>function</span><span>f</span><span>()</span>{</span><span>static</span><span>$v</span> = <span>1</span>; }</code>
<code><span><span>class</span><span>bee</span>{</span><span>static</span><span>$v</span> = <span>1</span>; <span>static</span><span><span>function</span><span>f</span><span>()</span>{</span>} }</code>
<code><span><span>class</span><span>bee</span>{</span><span>static</span><span>public</span><span>$a</span> = <span>10</span>; <span>static</span><span>public</span><span><span>function</span><span>f</span><span>()</span>{</span><span>echo</span> get_class().<span>':'</span>; <span>echo</span><span>self</span>::<span>$a</span>.<span>'-'</span>; <span>echo</span><span>static</span>::<span>$a</span>; } } <span><span>class</span><span>lig</span><span>extends</span><span>bee</span>{</span><span>static</span><span>public</span><span>$a</span> = <span>20</span>; } <span>echo</span> bee::f(); <span>echo</span><span>'<br>'</span>; <span>echo</span> lig::f();</code>
オブジェクト指向の 3 つの主要なアイデア
以上、PHP の特徴を含めて紹介しましたが、PHP チュートリアルに興味のある友人の参考になれば幸いです。