php中有没有像java类中的静态成员变量之类的,怎么实现?

解决方案 »

  1.   

    <?php 
    function test(){
        static $a = 1;
        $a ++;
        return $a;
    }
    echo test();//2
    echo test();//3
    ?>
      

  2.   

    ci里有个load_class的函数的, 那个应该就是你所说的静态变量类, 专门用来存放重复使用的要声明的对象
      

  3.   

    有,用static定义,不能用特定对象调用。例如:<?php
    class test
    {
        private static num = 0;    function _constructor()
        {
            self::num++;  
        }    static function getNum()
        {
            return self::num;
        }
    }$obj = new test();
    echo test::getNum();$obj1 = new test();
    echo test::getNum();
    ?>
      

  4.   

    好几个错误呢。
    public const $num = 5;
    常量
    return self::num;
    静态属性
    publi static $num = 5;return self:$num;
      

  5.   

    由于php工作方式的局限 php 不能实现 Java 中完全意义的 静态成员变量