PHP之static

WBOY
Libérer: 2016-07-29 09:02:46
original
1217 Les gens l'ont consulté

static是属于类本身的,是实例化对象所共有的

使用形式:

static $val;
static function func(){}

调用形式:

类名::$val;
类名::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>
Copier après la connexion

PHP之static

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

以上就介绍了PHP之static,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal