PHP学习第三天:类

来源:互联网 发布:python开发网页怎么样? 编辑:程序博客网 时间:2024/05/19 00:37

        这些文章都是用来记录学习PHP经历的,会有很多bug和错误,参考需谨慎。

        工作第三天。

<?PHPclass B{    private $arr = array();    private $action = "";    public function run()    {        $str = $_SERVER["QUERY_STRING"];        $str = preg_split("/&/", $str);        foreach ($str as $var) {            list($k, $v) = array("", "");            if (strstr($var, "=")) {                list($k, $v) = preg_split("/=/", $var);            } else {                $k = $var;            }            if ($k == 'r') $this->action = $v;            else $this->arr[$k] = $v;        }        $all = get_class_methods(get_class($this));        if (!in_array($this->action, $all)) {            echo "no this function" . "<br>";            die;        }        $work = $this->action;        $this->$work();    }    public function login()    {        echo "login" . "<br>";    }    public function logout()    {        echo "logout" . "<br>";    }    public function anything()    {        echo "anything" . "<br>";    }    public function xfruit()    {        echo "{\"errcode\":0,\"errmsg\":\"ok\",\"data\":{\"key\":\"welcome xfruit\"}} ";    }}$test = new B();$test->run();?>


0 0