Home > Backend Development > PHP Tutorial > Getting Started with PHP 7 Access to Static Properties

Getting Started with PHP 7 Access to Static Properties

WBOY
Release: 2016-07-28 08:26:13
Original
1141 people have browsed it

Use self::field inside the class
External use class name::field

<code><span><span><?php</span><span><span>class</span><span>StaticTest</span>{</span><span>public</span><span>static</span><span>$data</span> =<span>0</span>;
        <span>public</span><span><span>function</span><span>append</span><span>()</span> {</span><span>//类内部访问静态方法或属性 使用self::</span><span>//在其他语言中 一般是直接$data++;</span><span>self</span>::<span>$data</span>++;
        }
    }

    <span>$p</span> = <span>new</span> StaticTest();
    <span>$p</span>->append();
    <span>$p2</span> = <span>new</span> StaticTest();
    <span>$p2</span>->append();
    <span>//外部访问类中的静态方法或属性 类名::字段</span><span>echo</span>  StaticTest::<span>$data</span>;<span>//2</span><span>?></span></span></span></code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the access to static attributes in PHP Getting Started 7, including the content. 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