Features like PHP

WBOY
Release: 2016-07-29 09:01:31
Original
1001 people have browsed it

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>
Copy after login

Features like PHP

static late static binding

static has 3 different meanings of syntax

  • static variables in functions
<code><span><span>function</span><span>f</span><span>()</span>{</span><span>static</span><span>$v</span> = <span>1</span>;
}</code>
Copy after login
  • static members in classes
<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>
Copy after login
  • in methods Dynamically specify the 'current class', which is different from self. static represents the class that calls this method (dynamic), and self refers to the class where its code is located (static)
<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>
Copy after login

Features like PHP

Three major object-oriented ideas

  • Package
    It is to encapsulate the data and try not to show it to others. It can be considered that the most basic encapsulation is to encapsulate a lot of data in a class, but more strictly speaking, it is to make the attributes private as much as possible and provide operations to the outside through shared methods. .
  • Inheritance
  • Polymorphism
    Usually refers to an object using the same method to obtain different results
    It also means that different objects use the same method to get different results
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!