静态成员函数内的类实例

时间:2016-07-13 19:18:02

标签: php function class

我为我的服务器帐户构建了用户类。编写一个调用类实例本身的add()函数是否聪明?这不是一个错误的方法吗?

class cUser 
{
    private $login, $pass;   
    public static $users = array(), $userstmp, $datatmp, $usernew;   
    private static $datafile = "CuserData.txt";     

function __construct() 
{
    $this->login = $_POST['slogin'];
    $this->pass = $_POST['spass'];
}

public static function userAdd () 
{
    self::$usernew = new cUser();    //       <--- HERE ---<
    self::$users[ self::$usernew->login ] = self::$usernew;
    self::dataStore();
}
}

0 个答案:

没有答案