Home >Backend Development >PHP Tutorial >Features like PHP
Object downward passing feature
When an object calls an instance method, and then statically calls a method of another class in the method, the object in the source method (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 has 3 different meanings of syntax
<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>
Three major object-oriented ideas
The above has introduced the features of PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.