Home > Article > Backend Development > Static variable index of PHP class, php static variable index_PHP tutorial
Directly enter the code
<?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; ?>
Originally I thought the result should be
<span>1</span> ----------------------------------------------------- <span>1</span>
But I was wrong, The correct result is
<span>1</span> ---------------------------------------------------------------------------------- <span>2</span>
If you haven’t learned the basics well, make up for it as soon as possible