PHP static

WBOY
WBOYOriginal
2016-07-29 09:02:461222browse

static belongs to the class itself and is common to instantiated objects.

Usage form:

static $val;
static function func(){}

Calling form:

Class name: :$val;
Class name: :func();

<code><span><span><?php </span><span><span>class</span><span>sta</span>{</span><span>public</span><span>$temp</span> = <span>123</span>;
    <span>static</span><span>$type</span> = <span>100</span>;
    <span>static</span><span><span>function</span><span>stat</span><span>()</span>{</span><span>$me</span> = <span>new</span><span>self</span>;
        <span>//静态方法中不能使用this关键字</span><span>echo</span><span>'common val:'</span>.<span>$me</span>->temp.<span>""</span>;
        <span>echo</span><span>'static val:'</span>.sta::<span>$type</span>.<span>"<hr>"</span>;
        <span>echo</span><span>'static val:'</span>.<span>$me</span>::<span>$type</span>.<span>"<hr>"</span>;
        <span>//静态方法中亦不可调用普通方法</span>
    }
}

<span>echo</span><span>'sta:'</span>.sta::<span>$type</span>.<span>""</span>;
<span>echo</span> sta::stat();

<span>$a</span> = <span>new</span> sta();
<span>echo</span><span>'a:'</span>.<span>$a</span>::<span>$type</span>.<span>""</span>;

<span>$b</span> = <span>new</span> sta();
<span>$a</span>::<span>$type</span> = <span>200</span>;
<span>echo</span><span>'b:'</span>.<span>$b</span>::<span>$type</span>.<span>""</span>;</span></span></code>

PHP static

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced static in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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