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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:13:02
Original
811 people have browsed it

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;
?>
Copy after login

Originally I thought the result should be

<span>1</span>
-----------------------------------------------------
<span>1</span>
Copy after login

But I was wrong, The correct result is

<span>1</span>
----------------------------------------------------------------------------------
<span>2</span>
Copy after login

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 =...
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template