doyhq66282 2015-08-10 09:19
浏览 45

将属性/参数添加到类中的现有方法

I have a class admin user which has some rights to modify user data. I want to add two or more attributes to this method to complete the required functionality.

function update_user_by_admin($new_level, $user_id, $def_pass, $new_email, $active, $confirmation = "no", $staff_salary, $set_duty_timings) {
    $this->user_found = true;
    $this->user_access_level = $new_level;
    $this->set_staff_salary=$staff_salary;
    if ($def_pass != "" && strlen($def_pass) < 4) {
        $this->the_msg = "Password is too short use the min. of 4 chars.";
    } else {
        if ($this->check_email($new_email)) {
            $sql = "UPDATE %s SET access_level = %d, email = '%s', active = '%s', salary='salary'";
            $sql .= ($def_pass != "") ? sprintf(", pw = '%s'", md5($def_pass)) : "";
            $sql .= " WHERE id = %d";
            $sql_compl = sprintf($sql, $this->table_name, $new_level, $new_email, $active, $user_id);
            if (mysql_query($sql_compl)) {
                $this->the_msg = "Data is modified for user with id#<b>".$user_id."</b>";
                if ($confirmation == "yes") {
                    if ($this->send_confirmation($user_id)) {
                        $this->the_msg .= "<br>...a confirmation mail has been sent to the user.";
                    } else {
                        $this->the_msg .= "<br>...ERROR no confirmation mail is sent to the user.";
                    }
                }
            } else {
                $this->the_msg = "Database error, please try again!";
            }
        } else {
            $this->the_msg = "The e-mail address is invalid!";
        }
    }
}

how do I add new parameter code here?

  • 写回答

2条回答 默认 最新

  • douguai4653 2015-08-10 09:22
    关注

    Your choices are to edit the class itself, or to code a new class that inherits from the class and implements your two extra methods.

    If you go for the inheritance approach, you would then need to update any code that instantiates that class and make it instantiate your class instead as required.

    http://php.net/manual/en/language.oop5.inheritance.php

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)