Home  >  Article  >  Backend Development  >  Static variable index of PHP class, php static variable index_PHP tutorial

Static variable index of PHP class, php static variable index_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:13:02758browse

Static variable index of PHP class, php static variable index

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917483.htmlTechArticleStatic variable index of PHP class, php static variable index is directly uploaded to the code?phpclass example{ public static $pa; public $pb; public function __construct(){ $this-pb = ++self::$pa; }}$a =...
Statement:
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