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>
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.