Home > php教程 > php手册 > PHP 类的静态变量索引,php静态变量索引

PHP 类的静态变量索引,php静态变量索引

WBOY
Release: 2016-06-13 09:20:09
Original
783 people have browsed it

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

本来想结果应该是

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

可是我错了,正确的结果是

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

基础没学好,赶快补补

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template