php static解决思路

WBOY
Release: 2016-06-13 12:39:31
Original
729 people have browsed it

php static
RT,用CI框架在写一个php网页,现发现static关键字不太会用,简化代码如下:

<br />
class A extends CI_Controller{<br />
    private static $num = 0;<br />
    public function f1(){<br />
        self::$num = 1;<br />
        this->load->view('v1');<br />
    }<br />
    public function f2(){<br />
        if(self::$num === 1){<br />
            this->load->view('v2');            <br />
        }else{<br />
            this->load->view('v3');<br />
        }<br />
    }<br />
}<br />
Copy after login

刚开始我们访问函数f1,在f1中跳转到页面v1,然后在v1中又跳回f2,但是此时的num已经被重置了,会跳转到v3,这是为什么呢?php中的static不彻底吗?

php static oop
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!