Maison > Article > développement back-end > PHP 类的静态变量索引,php静态变量索引_PHP教程
直接上代码
<?php class example{ public static $pa; public $pb; public function __construct(){ $this->pb = ++self::$pa; } } $a = new example; $b = new example; echo $a->pb; echo '<hr/>'; echo $b->pb; ?>
本来想结果应该是
<span>1</span> ----------------------------------------------------- <span>1</span>
可是我错了,正确的结果是
<span>1</span> ---------------------------------------------------------------------------------- <span>2</span>
基础没学好,赶快补补